1、靜態方法和靜態代碼塊和靜態變量同級會按順序執行 新建類的時候常量如果是方法會執行一遍,父類方法被重寫會執行子類的方法
變量方法和代碼塊同級 順序執行
class Son extends Father{
private int i = test();
private static int j = method();
static{
System.out.println("6");
}
Son(){
System.out.println("7");
}
{
System.out.println("8");
}
@Override
public int test(){
System.out.println("9");
return 1;
}
public static int method(){
System.out.println("10");
return 1;
}
public static void main(String[] args) {
Son son = new Son();
System.out.println();
Son son1 = new Son();
}
}
class Father{
private int i = test();
private static int j = method();
static{
System.out.println("1");
}
Father(){
System.out.println(2);
}
{
System.out.println(3);
}
public int test(){
System.out.println(4);
return 1;
}
public static int method(){
System.out.println(5);
return 1;
}
}
5
1
10
6
9
3
2
9
8
7
9
3
2
9
8
7
AllReview——SEPart01
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.