Difference between Early and Late Binding in Java
Early Binding: The binding which can be resolved at compile time by the compiler is known as static or early binding. Binding of all the static, private and final methods is done at compile-time.
Example:
public class NewClass { public static class superclass { static void print() { System.out.println("print in superclass."); } } public static class subclass extends superclass { static void print() { System.out.println("print in subclass."); } } public static void main(String[] args) { superclass A = new superclass(); superclass B = new subclass(); A.print(); B.print(); } } |
print in superclass. print in superclass.
Late binding: In the late binding or dynamic binding, the compiler doesn’t decide the method to be called. Overriding is a perfect example of dynamic binding. In overriding both parent and child classes have the same method.
Example:
public class NewClass { public static class superclass { void print() { System.out.println("print in superclass."); } } public static class subclass extends superclass { @Override void print() { System.out.println("print in subclass."); } } public static void main(String[] args) { superclass A = new superclass(); superclass B = new subclass(); A.print(); B.print(); } } |
print in superclass. print in subclass.
Difference table between early and late binding:
| Early Binding | Late Binding |
|---|---|
| It is a compile-time process | It is a run-time process |
| The method definition and method call are linked during the compile time. | The method definition and method call are linked during the run time. |
| Actual object is not used for binding. | Actual object is used for binding. |
| For example: Method overloading | For example: Method overriding |
| Program execution is faster | Program execution is slower |
Recommended Posts:
- Static vs Dynamic Binding in Java
- Java Architecture for XML Binding ( JAXB ) | Set-1
- JavaScript | Function binding
- AngularJS | Data Binding
- Difference between x++ and x=x+1 in Java
- Difference between super() and this() in java
- Difference between for and while loop in C, C++, Java
- Difference between for and do-while loop in C, C++, Java
- Difference between while and do-while loop in C, C++, Java
- Difference between Groovy and Java
- Difference between Java and JavaScript
- Difference between Java and C language
- Difference between an Iterator and ListIterator in Java
- Difference between Arrays and Collection in Java
- Difference between ArrayList and HashSet in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



