java :can not be cast
//这个是A类public class A {
public void test1(){
System.out.println("我是testA方法");
}
}
//这个是B类
public class B extends A {
public void test1(){
System.out.println("我是bTest");
}
public void test2(){
System.out.println("我是btest1");
}
}
//驱动类
public class AbAPP {
public static void main(String[] args){
B b = (B)new A();
A a = new B();
b.test1();
b.test2();
a.test1();
}
}
// 可是运行后 我是Eclipse中运行的 提示:Exception in thread "main" java.lang.ClassCastException: A cannot be cast to B
at AbAPP.main(AbAPP.java:4)
真郁闷!