7
从父类到子类的显式转换
public class Animal { public void eat() {} } public class Dog extends Animal { public void eat() {} public void main(String[] args) { Animal animal = new Animal(); Dog dog = (Dog) animal; } } 分配Dog dog = (Dog) animal;不会产生编译错误,但在运行时会产生ClassCastException。为何编译器无法检测到此错误?