class GrandFather{
GrandFather(){
System.out.println("the GrandFather constructor is initialized");
}
static{
System.out.println("the GrandFather static filed is initialized");
}
}
class Father extends GrandFather{
Father(){
System.out.println("the Father constructor is initialized!");
}
static{
System.out.println("the Father static filed is initialized");
}
}
public class Son extends Father {
public Son(){
System.out.println("the Son constructor is initialized");
}
static{
System.out.println("the Son static filed is initialized");
}
public static void main(String[] args) {
Son son = new Son();
}
}
public class Test
{
/**
* @param args
*/
private int i=getValue();//第2行
private int j = 10;
int getValue(){
return j;
}
public static void main(String[] args) {
System.out.print(new Test().i);//第9行
}
}
很显然,这个例子在执行到上面的第4步时,只执行了a,b两步,而第三步 private int j = 10,在i被调用时还没被执行