Creating References Using Inheritance Hierarchies

AP Computer Science A· difficulty 4/5

<code>if (obj instanceof B) { B b = (B) obj; b.someBMethod(); } </code></pre>

  • A

    Idiomatic safe downcast pattern

    check_circle
  • B

    Compile error

  • C

    Cannot use instanceof

  • D

    Always crashes

Explanation

Standard guarded downcast.

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

Related questions