Overriding Methods

AP Computer Science A· difficulty 2/5

public abstract class Shape {
    public abstract double area();
}
public class Circle extends Shape {
    private double r;
    public Circle(double radius) { r = radius; }
    // no area method defined
}

What is the result of compiling Circle?

  • A

    Compiles fine; area() returns 0

  • B

    Compiles but throws RuntimeException

  • C

    Compile error: Circle must implement area() or be declared abstract

    check_circle
  • D

    Compiles only with a warning

Explanation

A non-abstract subclass of an abstract class must implement all inherited abstract methods. Circle does not implement area(), so it must either implement it or be declared abstract.

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

Related questions