ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

Which run-time mechanism lets a call through a base-class pointer invoke the correct derived-class override in C++?

  1. A. Function overloading resolved by the compiler
  2. B. Name mangling of the function signature
  3. C. The C preprocessor rewriting the call
  4. D. A virtual function table (vtable) and a hidden vptr in each polymorphic object

Correct answer: D. A virtual function table (vtable) and a hidden vptr in each polymorphic object

Each class with virtual functions gets a vtable of function pointers; every object of that hierarchy carries a hidden vptr to its own class's vtable, which the call is indirected through at run time.

More OOP with C++ and Java questions

Exams that ask this topic