Multiple choice technology programming languages

package constructors; class A { A() { System.out.println("I am in A"); } } class B extends A { B() { System.out.println("I am in B"); } } class C extends B { C() { System.out.println("I am in C"); } } public class TestConstructor1 { public static void main(String[] args) { C c = new C(); } }

  1. I am in A I am in B I am in C

  2. I am in B I am in C

  3. I am in C I am in B

  4. I am in C

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When C c = new C() executes, Java's constructor chaining rules apply. C() implicitly calls super() which invokes B(), which implicitly calls super() to invoke A(). Each constructor prints its message: A prints "I am in A", then B prints "I am in B", then C prints "I am in C". The output is the concatenation of all three messages in order: "I am in A I am in B I am in C". This demonstrates how Java ensures parent constructors complete before child constructors execute.