public class Animal {}
public class Dog extends Animal {}
public class Cat extends Animal {}
Animal a = new Cat();
Dog d = (Dog) a;What happens?
- A
Compile-time error
- B
NullPointerException
- Ccheck_circle
ClassCastException at runtime
- D
Runs successfully
Explanation
The cast compiles because Dog is a subclass of Animal, but at runtime the object is actually a Cat, causing ClassCastException.