想不到什么好标题 直接看代码好了
父类
public class Father {
private int i = test1();
private static int j = method();
public int test1(){
System.out.println("1");
return 1;
}
public static int method(){
System.out.println("2");
return 1;
}
{
System.out.println("3");
}
public Father(){
System.out.println("4");
}
static {
System.out.println("5");
}
}
子类
public class Son extends Father{
private int i = test2();
private static int j = method();
public int test2(){
System.out.println("6");
return 1;
}
public static int method(){
System.out.println("7");
return 1;
}
static {
System.out.println("8");
}
{ //代码块是优先于构造器的
System.out.println("9");
}
public Son(){
System.out.println("10");
}
public static void main(String[] args) {
Son son = new Son();
System.out.println();
Son son1 = new Son();
}
}
/*output
2 5 7 8 1 3 4 6 9 10
1 3 4 6 9 10
*/