下面这个程序运行的结果让人不理解。
运行结果为:
Parent is creating..//不理解
Son is eat: 0//不理解
Son is creating..
Son is eat: 1
主要是前2句不理解。请高手详细说明之。谢谢
Java code
/**
*Parent.java
*/
public class Parent {
private int eatID=0;
public Parent(){
System.out.println("Parent is creating..");
eat();
}
public void eat(){
System.out.println("Parent is eat: "+eatID);
}
}
Java code
/**
*Son.java
*/
public class Son extends Parent {
private int eatID=1;
public Son(){
System.out.println("Son is creating..");
eat();
}
public void eat(){
System.out.println("Son is eat: "+eatID);
}
@SuppressWarnings(value={"unused"})
public static void main(String[] args){
Parent p=new Son();
}
} |
|