ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
Which statement about C++ vtables is correct for a class with multiple virtual functions?
- A. Vtables only exist for classes with no data members
- B. All of a class's virtual functions share one single vtable for that class, indexed by function slot
- C. The vtable is recreated for every object individually
- D. Each virtual function gets its own separate vtable
Correct answer: B. All of a class's virtual functions share one single vtable for that class, indexed by function slot
A class gets exactly one vtable listing all of its virtual functions; every instance's vptr points to that same shared table.
More OOP with C++ and Java questions
- Class A's constructor declares throws IOException. Class B extends A. What must every constructor of B do about this checked exception?
- What access modifier and finality does a field declared directly inside a Java interface implicitly have?
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- What does the 'Rule of Five' in modern C++ say?
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- java class Base { int v = 1; } class Derived extends Base { int v = 2; } // main: Base b = new Derived(); System.out.print(b.v); What is…