AP Computer Science A · Topic 9.4

super Keyword Practice

Part of Inheritance.

Practice questions

12

Want a predicted score for the whole AP CSA exam? Take the 20-question diagnostic and Lumi will plan the rest.

Sample questions

5 of 12 — sign in to practice the rest with adaptive difficulty and mastery tracking.

  1. Sample 1difficulty 3/5

    <code>super(arg)</code> calls

    • A

      Compile error

    • B

      A static method

    • C

      The current class's other constructor

    • D

      The parent class constructor

      check_circle

    Why

    Use <code>super(args)</code> as first statement of subclass constructor.

  2. Sample 2difficulty 3/5

    public class A {
        public String hello() { return "Hi from A"; }
    }
    public class B extends A {
        public String hello() { return super.hello() + " and B"; }
    }
    System.out.println(new B().hello());

    What is printed?

    • A

      Stack overflow error

    • B

      and B

    • C

      Hi from A and B

      check_circle
    • D

      Hi from A

    Why

    <code>super.hello()</code> calls A's version, returning "Hi from A". Then " and B" is appended.

  3. Sample 3difficulty 3/5

    public class A {
        public String describe() { return "A"; }
    }
    public class B extends A {
        public String describe() { return super.describe() + "B"; }
    }
    public class C extends B {
        public String describe() { return super.describe() + "C"; }
    }
    // Usage:
    A obj = new C();
    System.out.print(obj.describe());

    What is printed?

    • A

      AC

    • B

      C

    • C

      ABC

      check_circle
    • D

      CBA

    Why

    C calls super.describe (B's), which calls super.describe (A's = "A"), then appends "B" → "AB", then appends "C" → "ABC".

  4. Sample 4difficulty 3/5

    public class A {
        public String label() { return "A"; }
        public String tag() { return label(); }
    }
    public class B extends A {
        public String label() { return "B"; }
    }
    // Usage:
    B b = new B();
    System.out.print(b.tag());

    What is printed?

    • A

      Compile error: tag missing in B

    • B

      AB

    • C

      A

    • D

      B

      check_circle

    Why

    tag() is inherited and calls label() (this.label()). Dynamic dispatch invokes B's label(), printing "B".

  5. Sample 5difficulty 3/5

    public class A {
        public String greet() { return "hello"; }
    }
    public class B extends A {
        public String greet() { return super.greet() + " world"; }
    }
    // Usage:
    B b = new B();
    System.out.print(b.greet());

    What is printed?

    • A

      world

    • B

      hello hello world

    • C

      hello world

      check_circle
    • D

      Stack overflow

    Why

    super.greet() calls A's greet returning "hello". B's greet appends " world", so "hello world" is printed.