Java code execution order
To sum up: is static priority higher than the priority of non-static, static and non-static in the parent class is a subclass of higher priority than the priority.
The constructor can be attributed to non-static.
[No difference between static and static variables block fixed priority, who first defined, whoever performs]
1. Sample Code
public class TestInitialSeq extends Father {
public static Print static_var_son = new Print("子类静态变量");
public Print var_son = new Print("子类非静态变量");
static {
System.out.println("子类静态代码块");
}
{
System.out.println("子类非静态代码块");
}
public TestInitialSeq() {
System.out.println("子类构造函数");
}
public static void main(String[] args) {
new TestInitialSeq();
}
}
class Father {
public Print var_father = new Print("父类非静态变量");
static {
System.out.println("父类静态代码块");
}
public static Print static_var_father = new Print("父类静态变量");
{
System.out.println("父类非静态代码块");
}
public Father() {
System.out.println("父类构造函数");
}
}
class Print {
public Print(String word) {
System.out.println(word);
}
}