class test {
public static void main(String[] args) {
Zi z = new Zi();
}
}
class Fu {
int a = 1;
static {
System.out.println("静态代码块Fu");
}
{
System.out.println("构造代码块Fu");
System.out.println("构造代码块fu执行时c的值"+this.c);//这一句会报错“找不到符号”
}
public Fu() {
System.out.println("构造方法Fu");
System.out.println("构造方法fu执行时a的值"+this.a);
}
}
class Zi extends Fu {
int c = 3;
static {
System.out.println("静态代码块Zi");
}
{
System.out.println("构造代码块Zi");
System.out.println("构造代码块Zi执行时c的值"+this.c);
}
public Zi() {
System.out.println("构造方法Zi");
System.out.println("构造方法Zi执行时c的值"+this.c);
}
}
如上,红色注释的那一行会报错。但是把它改为显示this.a的值则可以正常运行,感觉理解不了。。。。这大概和没弄清Java的继承机制有关吧,求大家指导下
|
|