Multiple choice technology programming languages

Why virtual functions are used ?

  1. To access derived class objects using base class pointer.

  2. To access base class objects using derived class pointer.

  3. To avoid ambiguity in inheritance.

  4. To create array of objects.

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

Virtual functions enable runtime polymorphism. When you call a virtual function through a base class pointer, the actual derived class implementation is executed based on the object's dynamic type, not the pointer's static type. This allows base class pointers to correctly invoke derived class behavior.