Dynamic Binding in Java Programming

Dynamic Binding in Java Programming

Previous Home Next

 

Dynamic Binding refers to the case where compiler is not able to resolve the call and the binding is done at run time only.Dynamic binding is also called late binding .or run time binding ,binding of method overriding.

When a language implements late binding, there must be some mechanism to
 determine the type of the object at run-time and to call the 
appropriate method. 

All method binding in Java uses late binding unless a method has been declared final. This means
that you ordinarily donít need to make any decisions about whether late binding will occur Ė it happens automatically.
 
SuperClass superClass1 = new SuperClass();
SuperClass superClass2 = new SubClass();
...

superClass1.someMethod(); // SuperClass version is called
superClass2.someMethod(); // SubClass version is called
....//here has to decide which version is called at the run time
// therefore it is called run time binding


 
SuperClass superClass1 = new SuperClass();
SuperClass superClass2 = new SubClass();
...

superClass1.someMethod(); // SuperClass version is called
superClass2.someMethod(); // SubClass version is called
....//here has to decide which version is called at the run time
// therefore it is called run time binding


Previous Home Next