ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

Within a single derived class's own constructor body, in what order are its direct base class subobjects (assuming no virtual inheritance) and member subobjects constructed?

  1. A. Whichever order appears first in the member-initializer list
  2. B. All bases and members interleaved in file order across the whole translation unit
  3. C. All direct base classes first, in the order they are listed in the class declaration, then all member subobjects in the order they are declared, regardless of the order written in the member-initializer list
  4. D. Member subobjects first, then base classes

Correct answer: C. All direct base classes first, in the order they are listed in the class declaration, then all member subobjects in the order they are declared, regardless of the order written in the member-initializer list

C++ fixes construction order to base classes (declaration order), then members (declaration order); the programmer's initializer-list order has no effect on this sequencing, only on which values are used.

More OOP with C++ and Java questions

Exams that ask this topic