ProgrammingHardStatement-count style · Product-company MCQ pattern

How many of these are correct about C++ virtual functions on a typical implementation? (i) Each class with virtual functions has a table of function pointers (vtable). (ii) Each object of such a class carries a hidden pointer to its class's vtable. (iii) A constructor can be declared virtual. (iv) A static member function can be virtual.

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: B. Only two

(i) and (ii) describe the usual vtable/vptr mechanism, which is why such objects grow by one pointer. (iii) false: constructors cannot be virtual (destructors can). (iv) false: static functions have no this object to dispatch on. So two.

More OOP with C++ and Java questions

Exams that ask this topic