Thursday, 8 March 2012

Dynamic method dispatch

•Dynamic method dispatch is the mechanism in which the call to a overriden method is resolved at run-time rather than compile time.
•Dynamic method dispatch provides run-time polymorphism in Java.
•Overriding is the concept that supports dynamic method dispatch.
•A super class variable can refer a subclass object like:

SuperClass obj = new SubClass();


•When a superclass variable is used to refer a subclass object the following characteristics hold:
1) The superclass variable can access only the members of the superclass. It cannot access the members specific to the subclass. That is the members that can be accessed is determined by the type of reference.
2) In case of overrding(methods with signature), the method that is going to be invoked is based on the type of object that is being assigned to the reference variable.



Advantages of overriding:

•Provides run-time polymorphism.
•Provides code reusability.
•Provides a way for the subclasses to implement the methods in the superclass in their own way.
•Provides robustness/reliability.

1 comment:

  1. Dynamic method dispatch is a mechanism by which a call to an overridden method is resolved at runtime. This is how java implements runtime polymorphism. java training in chennai | chennai's no.1 java training in chennai | best java institute in chennai

    ReplyDelete