Home > Java > javaTutorial > body text

The difference between static binding and dynamic binding in Java

WBOY
Release: 2023-08-27 23:09:08
forward
1429 people have browsed it

The difference between static binding and dynamic binding in Java

#Binding is a mechanism that creates a link between a method call and the actual implementation of the method. According to the concept of polymorphism in Java, objects can have many different forms. The object form can be resolved at compile time and run time. If the link between method invocation and method implementation is resolved at compile time, we call it static binding; if it is resolved at runtime, we call it dynamic binding. Dynamic binding uses objects to resolve bindings, while static binding uses classes and fields' types.

##Dynamic binding uses objects to resolve the binding3ExampleOverload It is an example of static bindingMethod overriding is an example of dynamic binding4.Method typePrivate, final Use static binding for static methods and variablesUse dynamic binding for virtual methodsStatic and dynamic binding examples
public class FastFood {
   public void create() {
      System.out.println("Creating in FastFood class");
   }
}
public class Pizza extends FastFood {
   public void create() {
      System.out.println("Creating in Pizza class");
   }
}
public class Main {
   public static void main(String[] args) {
      FastFood fastFood= new FastFood();
      fastFood.create();
      //Dynamic binding
      FastFood pza= new Pizza();
      pza.create();
   }
}
Copy after login
Old gentleman. no.

Key

Static binding

Dynamic binding

##1 p>

##Basic

Resolved at compile time

Resolved at runtime

2

Parsing mechanism

Static binding uses the types of classes and fields

td>

The above is the detailed content of The difference between static binding and dynamic binding in Java. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template