执行顺序如下:
静态初始化块->初始化块->被调用的构造器->当前构造器
执行代码如下:
public class Shape {
{
System.out.println("single block");
}
static
{
System.out.println("static block");
}
public Shape(){
System.out.println("constructor");
}
public Shape (int x){
this();
System.out.println("constructor "+x);
}
public static void main(String[] args) {
new Shape(2);
}
}