//子類建立 先調用父類的 構造器, 調用父類構造器以前,先看有沒有靜態化方法(包括父子全部 先父類 再子類),父類的實例變量初始化以後才父類的構造器。
//同理子類的 實例變量初始化後才子類的構造器。 spa
public class ChildObjectTest extends Parent{
private int k;
private static int b;
{
System.out.println("kkk");
k++;
}
static {
b = b+19;
System.out.println("b===="+b);
}
{
System.out.println("tt");
k++;
System.out.println(k);
}
public ChildObjectTest(){
System.out.println("childObjectTest....");
}
public static void main(String[] args) {
new ChildObjectTest().test();
new ChildObjectTest().test2();
}
public void test(){
System.out.println(k);
System.out.println(b);
}
public void test2(){
System.out.println("test2...........static is only ..........initializing for everyone......");
}
} it
class Parent{
//靜態代碼塊
static{
System.out.println("supper static");
}
//實例變量初始化
{
System.out.println("supper initializing ");
}
public Parent(){
System.out.println("supper parent");
}
} class
------------------------------------------------------------ test
supper static
b====19
supper initializing
supper parent
kkk
tt
2
childObjectTest....
2
19
supper initializing
supper parent
kkk
tt
2
childObjectTest....
test2...........static is only ..........initializing for everyone...... 變量