Welcome to Westonci.ca, your go-to destination for finding answers to all your questions. Join our expert community today! Get expert answers to your questions quickly and accurately from our dedicated community of professionals. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

If a base class pointer, p, points to a derived class instance, and both base and derived classes have a method void doIt() which takes no parameters, then p->doIt() will invoke the derived class version:__________

a. only if both the base class method and the derived class method are declared virtual.
b. if the derived class method is declared virtual, but the base is not declared virtual.
c. if the base class method is declared virtual, even if the derived class method is not declared virtual.


Sagot :

Answer:

a. only if both the base class method and the derived class method are declared virtual.

Explanation:

The parameters will invoke derived class version, because objected pointed to determine which method is called. The base and derived class are declared virtual Overriding feature allows subclass and derived class to provide implementation.