Dynamic dispatch - OOP Basics
Q. Dynamic dispatch is a feature that- Published on 19 Oct 15
a. selects which polymorphic operation to call at run time
b. selects which polymorphic operation to call at compile time
c. Both a and b
ANSWER: selects which polymorphic operation to call at run time
Dynamic dispatch also known as message passing is a process of selecting a procedure to run in response to a method call by looking for the method (function) in the table associated with the object, at run time. It distinguishes an object from a module which has fixed implementations for all instances i.e. static dispatch. Dynamic dispatch has usage in Object oriented programming languages when different classes have different implementations of same function call due to inheritance.
For example there are three classes. Class X- the base class, Class Y and Class Z- the derived class and all of them have a function call- show( ), then dynamic dispatch selects which implementation of function to call at run time.