关于Java强制类型转化问题
这是我随便写的一个程序,想检测下向下转型public class Animal {
public String animal="animal";
}
public class Dog extends Animal {
public String dog="dog";
}
public class Text {
public static void main(String[] args) {
Animal animal=new Animal();
Dog dog=(Dog)animal;
}
}
系统提示如下错误,不解,还请高手指点:
Exception in thread "main" java.lang.ClassCastException: Youjianqin.Animal cannot be cast to Youjianqin.Dog
at Youjianqin.Text.main(Text.java:17)