Overriding Methods

AP Computer Science A· difficulty 4/5

public class A {
    public static String name() { return "A"; }
}
public class B extends A {
    public static String name() { return "B"; }
}
A x = new B();
System.out.println(x.name());

What is printed?

  • A

    Compile-time error

  • B

    B

  • C

    A

    check_circle
  • D

    AB

Explanation

Static methods are NOT subject to dynamic dispatch. They are resolved by the declared (compile-time) type, which is A.

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

Related questions