Java – Dynamic Method Dispatch

Java – Dynamic Method Dispatch 2017-08-09T11:54:44+00:00

Java Dynamic Method Dispatch :

In java Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time, rather than compile time. Dynamic method dispatch is important because this is how Java implements run-time polymorphism.

method to execution based upon the type of the object being referred to at the time the call occurs. Thus, this determination is made at run time.
In other words, it is the type of the object being referred to (not the type of the reference variable) that determines which version of an overridden method will be executed.

EX :


Output :
Inside A’s callme method
Inside B’s callme method
Inside C’s callme method
Here reference of type A, called r, is declared.
The program then assigns a reference to each type of object to r and uses that reference to invoke callme( ).
As the output shows, the version of callme( ) executed is determined by the type of object being referred to at the time of the call.

Prev Next