<code>Animal a = new Dog(); Dog d = (Dog) a;</code> is
- A
Throws compile error
- B
Compile-time error
- C
Always safe
- Dcheck_circle
Runtime check; OK if a is actually Dog (else ClassCastException)
Explanation
Downcasts are checked at runtime.
AP Computer Science A· difficulty 4/5
<code>Animal a = new Dog(); Dog d = (Dog) a;</code> is
Throws compile error
Compile-time error
Always safe
Runtime check; OK if a is actually Dog (else ClassCastException)
Explanation
Downcasts are checked at runtime.
Want 10 more like this — adaptive to your weak spots?