Java 执行顺序
class T {
T() {
System.out.println("super construct");
}
{
System.out.println("super no static ");
}
static {
System.out.println("super static ");
}
}
public class E extends T {
E() {
System.out.println("construct");
}
static int a = 0;
{
System.out.println("no static c");
}
static {
System.out.println("static ");
}
public static void main(String args[]) {
System.out.println("后于静态代码段执行");
new E();
}
}
执行结果如下:
super static static 后于静态代码段执行 super no static super construct no static c construct