If A is a superclass, B is a subclass of A, and C is a subclass of B, in what…

2024

If A is a superclass, B is a subclass of A, and C is a subclass of B, in what order are the constructors of these classes called? (Assume the standard automatic superclass-constructor invocation used in mainstream OOP languages such as C++, Java, and C#.)

Answer: B. A, B, CIn a single-inheritance chain, under automatic (default) superclass-constructor invocation, a subclass's own constructor body only starts running after its…

  1. A.

    A, C, B

  2. B.

    A, B, C

  3. C.

    C, A, B

  4. D.

    C, B, A

  5. E.

    Question not attempted

Attempted by 511 students.

Show answer & explanation

Correct answer: B

In a single-inheritance chain, under automatic (default) superclass-constructor invocation, a subclass's own constructor body only starts running after its direct superclass's constructor has fully finished; applied link by link down a multi-level chain, this makes the topmost superclass finish first, with each subclass following its own direct parent. This is exactly the default constructor-chaining behaviour shared by C++, Java, and C# -- the assumption this question specifies -- so the order does not depend on which of these languages is meant.

  1. A is the topmost of the three classes named in the chain A → B → C, so among these three its constructor is the first to execute.

  2. B's only direct superclass is A, so B's constructor cannot begin until A's constructor has completed.

  3. C's only direct superclass is B, so C's constructor cannot begin until B's constructor has completed.

  4. Chaining these three dependencies together gives the overall execution order: A, then B, then C.

  • Working from the leaf upward gives the same result: constructing a C object needs its B part to already exist, which itself needs its A part to already exist -- so A must finish first, then B, then C, matching the forward derivation.

  • RPSC's official answer key for this Programmer (Paper II) 2024 paper lists this same option, "A, B, C", as the accepted response for this item.

Therefore, the constructors are called in the order A, B, C.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs

Loading lesson…