Overriding Methods

AP Computer Science A· difficulty 3/5

public class A {
    public final String greet() { return "hi"; }
}
public class B extends A {
    public String greet() { return "hello"; }
}

What occurs?

  • A

    Runtime error on B instantiation

  • B

    Compiles; B's greet replaces A's

  • C

    Compile error: cannot override final method

    check_circle
  • D

    Warning but compiles

Explanation

final methods cannot be overridden. B fails to compile.

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

Related questions