Early binding, which is tied to compile-time type before execution of the program, is less expensive to call, such as a C language with only a pre-binding method call.
Late binding refers to binding at run time based on the type of the object, also called dynamic binding or runtime binding. Implementing late binding requires some kind of mechanism support so that at runtime you can judge the type of the object, and the invocation overhead is larger than the previous binding.
The static method and the final method in Java (private belongs to the final method, the detailed explanation see "Java programming thought") belongs to the early binding, the subclass cannot rewrite the final method, and the member variables (both static and non-static) are also early bound. In addition to the static method and the final method (the private belongs to the final method) other methods belong to late binding, the runtime can judge the type of the object to bind. The verification program is as follows:
Class base{//member variables, subclasses also have the same member variable name as public String test= "Base Field"; Static methods, subclasses also have static methods of the same signature public static void Staticmethod () {System.out.println ("Base Staticmethod ()"); }//Subclasses will overwrite this method with public void Notstaticmethod () {System.out.println ("Base Notstaticmethod ()"); }}public class Derive extends base{public String test= "Derive Field"; public static void Staticmethod () {System.out.println ("Derive Staticmethod ()"); } @Override public void Notstaticmethod () {System.out.println ("Derive Notstaticmethod ()"); }//The value of the output member variable to verify that it is a pre-binding. public static void Testfieldbind (base base) {System.out.println (base.test); }//static method, verifying that it is a pre-binding. public static void Teststaticmethodbind (base base) {//the static method test () from the type Base should is ACC Essed in a static means//using Base.test () is more reasonable, where this representation is used for a more intuitive demonstration of early binding. Base.staticmethod (); }//Call a non-static method to verify that it is late-bound. public static void Testnotstaticmethodbind (base base) {Base.notstaticmethod (); } public static void Main (string[] args) {Derive d=new Derive (); Testfieldbind (d); Teststaticmethodbind (d); Testnotstaticmethodbind (d); }}/* program output: Base fieldbase staticmethod () Derive notstaticmethod () */
About early binding late binding in Java (Dynamic binding)