Writing Constructors for Subclasses

AP Computer Science A· difficulty 3/5

public class A {
    public A() { System.out.print("A "); }
}
public class B extends A {
    public B() { System.out.print("B "); }
}
public class C extends B {
    public C() { System.out.print("C "); }
}
// Usage:
C c = new C();

What is printed?

  • A

    C

  • B

    A B C

    check_circle
  • C

    C B A

  • D

    A C

Explanation

Constructors run from the top of the hierarchy down. Implicit super() calls fire first: A runs, then B, then C.

Want 10 more like this — adaptive to your weak spots?

Related questions