Polymorphism

AP Computer Science A· difficulty 4/5

<code>Animal[] zoo = {new Dog(), new Cat()};</code> is valid because

  • A

    Java widens primitive types

  • B

    Subclass references can be stored in superclass array

    check_circle
  • C

    Compile error actually

  • D

    Arrays accept anything

Explanation

Subtype-of-Animal references fit in Animal[].

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

Related questions