Writing Constructors for Subclasses

AP Computer Science A· difficulty 2/5

public class Base {
    public Base() { System.out.print("B "); }
}
public class Child extends Base {
    public Child() { System.out.print("C "); }
}
// ...
new Child();

What is printed?

  • A

    B

  • B

    C

  • C

    C B

  • D

    B C

    check_circle

Explanation

Java implicitly calls super() before the body of the subclass constructor, so Base prints first.

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

Related questions