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

2024

If A is a superclass and B is a subclass of it and C is subclass of B, in what order the constructors that make up the classes be called?

  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 372 students.

Show answer & explanation

Correct answer: B

In object-oriented programming, when a class inherits from another class, the constructor of the superclass is called before the constructor of the subclass. This ensures that the base class is properly initialized before the derived class.

Given that A is the superclass, B is a subclass of A, and C is a subclass of B, the inheritance hierarchy is A → B → C.

Step 1: The constructor of the topmost class A is called first.

Step 2: After A's constructor completes, the constructor of B is called.

Step 3: Finally, the constructor of C is called after B's constructor.

Thus, the correct order of constructor calls is A, B, C.

Explore the full course: Up Lt Grade Assistant Teacher 2025