#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.
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(); } }
Old gentleman. no. | Key | Static binding | Dynamic binding |
---|---|---|---|
##1p> |
##Basic |
Resolved at compile time |
Resolved at runtime |
2 |
Parsing mechanism |
Static binding uses the types of classes and fields | ##Dynamic binding uses objects to resolve the binding
|
Overload It is an example of static binding | |||
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!