总结:执行顺序如下:
1. 先执行父类静态代码块
2.子类静态代码块
3.父类代码块
4.父类构造函数
5.子类代码块
6.子类构造函数
public class First {
{
System.out.println("First code block");
}
static{
System.out.println("First static test");
}
public First(){
System.out.println("First gouzao");
}
}
public class Second extends First {
static{
System.out.println("Second static Test");
}
{
System.out.println("Second code block");
}
public Second(){
System.out.println("Second gouzao");
}
}
public class Login {
public static void main(String[] args){
new Second();
}
}
运行结果:
First static test
Second static Test
First code block
First gouzao
Second code block
Second gouzao