1.

Which is a must condition for virtual function to achieve runtime polymorphism?(a) Virtual function must be accessed with direct name(b) Virtual functions must be accessed using base class object(c) Virtual function must be accessed using pointer or reference(d) Virtual function must be accessed using derived class object onlyThis question was addressed to me in an international level competition.This intriguing question comes from Virtual Functions topic in section Member Functions & its Types of Object Oriented Programming

Answer» RIGHT answer is (c) VIRTUAL function MUST be accessed using pointer or reference

Easy explanation - The virtual functions must be called using pointer or reference. This is MANDATORY so that the intended function GETS executed while resolving the method at runtime. The must not be any ambiguity between the method of parent class and derived class.


Discussion

No Comment Found

Related InterviewSolutions