Creating Superclasses and Subclasses

AP Computer Science A· difficulty 2/5

public class A {
    public int doubleIt(int n) { return n * 2; }
}
public class B extends A { }
System.out.println(new B().doubleIt(7));

What is printed?

  • A

    Compile-time error

  • B

    7

  • C

    14

    check_circle
  • D

    0

Explanation

B inherits doubleIt from A.

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

Related questions