测试代码:
public class test4 {
{
System.out.println(1);
}
static {
System.out.println(2);
}
test4() {
System.out.println("构造器");
}
{
System.out.println(3);
}
void say() {
System.out.println("say");
}
{
System.out.println(4);
}
}
class t {
public static void main(String[] args) {
new test4().say();
}
}
输出结果:
2
1
3
构造器
say
一点结论:执行优先级,看代码和代码块所处的顺序位置没有关系
静态代码块>构造代码块>构造器>调用方法