代码块运行的优先级

package FatherAndSon;

/*
* 父类
*/
public class Father {

static {
System.out.println("这是父类中的静态代码块");
}

public Father() {
System.out.println("这是父类中的构造方法");
}

{
System.out.println("这是父类中的构造代码块1");
}
}

-----------------以下是子类-------------------------


package FatherAndSon;
/*
* 子类
*/
public class Son extends Father {
static {
System.out.println("这是子类中的静态代码块");
}

{
System.out.println("这是子类中的构造代码块");
}

public Son() {
System.out.println("这是子类中的构造方法");
}
}

--------------------测试打印------------------

package FatherAndSon;

public class Test01 {
public static void main(String[] args) {
Son son = new Son();
}
}

-----------------打印结果----------------------

这是父类中的静态代码块
这是子类中的静态代码块
这是父类中的构造代码块1
这是父类中的构造方法
这是子类中的构造代码块
这是子类中的构造方法

原文地址:https://www.cnblogs.com/Koma-vv/p/9546823.html