class Fu{
public int num = 10;
public Fu(){
System.out.println("fu");
}
}
class Zi extends Fu{
public int num = 20;
public Zi(){
System.out.println("zi");
}
public void show(){
int num = 30;
System.out.println(num);
System.out.println(this.num);
System.out.println(super.num);
}
}
class Test1_Extends {
public static void main(String[] args) {
Zi z = new Zi();
z.show();
}
}作者: 我是你岁哥❤环 时间: 2016-5-19 00:45
fu
zi
30
20
10
解释:
1、通过Zi z = new Zi(); 创建子类对象时,子类继承父类,先通过父类构造函数进行初始化,在由子类的构造函数初始化,所以先输出fu,在输出zi;
2、z.show(); 子类调用show方法中,