62,623
社区成员
发帖
与我相关
我的任务
分享
Father father = null;
System.out.println(“Nothing”);
father = new Father();
public class Test {
public static void main(String[] args){
Father father = new Father();
Son son1 = (Son)father; //此处抛出运行时异常ClassCastException,编译可以通过
son1.say();
Son son2 = new Son("Mike");
son2.say();
}
}
class Father{
}
class Son extends Father{
private String name;
public Son(String name){this.name=name;}
public void say(){
System.out.println("hello");
}
}