Multiple choice

If there is a pointer p to object of a base class and it contains the address of an object of derived class and both classes contain a virtual member function xyz(), then the statement p->xyz(); will cause the version of xyz() in the ___________ class to be executed.

  1. derived class

  2. base class

  3. produces compile time error

  4. produces runtime error

  5. none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Base b; Base *p; Derived d; p=&d; p->xyz(); as pointer is holding the address of derived class object and functions are defined virtual, derived class function xyz() is called.