私有静态方法执行完之后,执行静态代码块,接着执行final实例方法实例化,然后执行非静态代码块,最后执行构造器的初始化
public class A{
int count;
int count3=count2();
int count5=count1();
A(){
System.out.println("构造器");
}
static{
System.out.println("静态代码块");
}
{
System.out.println("非静态代码块");
}
private static int count1(){
System.out.println("私有静态方法");
return 1;
}
private final static int count2(){
System.out.println("final实例方法");
return 5;
}
}
test:
public class Demo {
public static void main(String[] args) {
A a =new A();//这里是静态代码块 调用是构造器进行初始化
}
}
result:
静态代码块
final实例方法
私有静态方法
非静态代码块
构造器