Creating Superclasses and Subclasses

AP Computer Science A· difficulty 2/5

public abstract class Animal {
    public abstract String sound();
}
// Usage:
Animal a = new Animal();

What occurs?

  • A

    Compiles fine

  • B

    Compiles and creates an Animal with null sound

  • C

    Compile error: Animal is abstract; cannot be instantiated

    check_circle
  • D

    Runtime error when sound() is called

Explanation

Abstract classes cannot be directly instantiated with new. The compiler reports an error.

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

Related questions