* A:案例演示
*
看程序写结果1
class Fu{
public int num = 10;
public Fu(){
System.out.println("fu"); //2
}
}
class Zi extends Fu{
public int num = 20;
public Zi(){
System.out.println("zi"); //3
}
public void show(){
int num = 30;
System.out.println(num); //30 4
System.out.println(this.num); //20 5
System.out.println(super.num); //10 6
}
}
class Test1_Extends {
public static void main(String[] args) {
Zi z = new Zi(); // 1
z.show();
}
}
看程序写结果2
class Fu {
static {
System.out.println("静态代码块Fu");
}
{
System.out.println("构造代码块Fu");
}
public Fu() {
System.out.println("构造方法Fu");
}
}
class Zi extends Fu {
static {
System.out.println("静态代码块Zi");
}