Dynamic Binding in Java
Dynamic Binding :
Association of method call to the method body is known as binding. Dynamic binding 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 same method.
Examples 1:
Output :
print in superclass. print in subclass.
Example 2:
Output :
This is the method of sub class
Static Binding or Early Binding:
The binding which can be resolved at compile time by compiler is known as static or early binding. The binding of static, private and final methods is compile-time.
Example :
Output :
Human walks Human walks