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
d. None

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.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)