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?
- A. Whichever order appears first in the member-initializer list
- B. All bases and members interleaved in file order across the whole translation unit
- 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
- 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
- Which statement correctly describes the typical cost of exceptions in C++?
- Why can a generic method not simply write new T[10] for a type parameter T in Java?
- java void f(int x) { System.out.print("int"); } void f(Integer x) { System.out.print("Integer"); } void f(Object... x) {…
- Why does adding a brand-new virtual function to a base class not increase the size of each object in that hierarchy (assuming objects…
- Which java.util.function functional interface best fits a lambda that takes one argument of type T and returns a boolean?
- A base class method is declared final in Java. What does this guarantee about calls to it through a base-class reference, regardless of…