62,620
社区成员
发帖
与我相关
我的任务
分享

public class Test{
public static void main(String args[])
{
//执行Father()==>Child1.show():此时父类的构造方法还未结束,子类的域m还没有初始化
Father n1=new Child1();
Father n2=new Child2();
}
}
class Father{
int m=5;
public Father(){
System.out.println("father constructor start");
this.show();
System.out.println("father constructor end");
}
void show(){
System.out.println("father show");
System.out.println("父");
}
}
class Child1 extends Father{
int m = 6;
public Child1(){
System.out.println("child1 constructor start");
this.show();
System.out.println("child1 constructor end");
}
void show(){
System.out.println("child1 show start");
System.out.println(m);
System.out.println("child1 show end");
}
}
class Child2 extends Father{
void show(){System.out.println(m);}
}