Creating References Using Inheritance Hierarchies

AP Computer Science A· difficulty 4/5

Continuing: <code>obj.someBMethod()</code> where someBMethod is only in B

  • A

    Returns null

  • B

    Compile error (reference type is A; method not in A)

    check_circle
  • C

    Throws exception

  • D

    Works at runtime

Explanation

Compile-time check uses reference type A; B-only method not visible.

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

Related questions