public class Element {
Element(String o){
System.err.println("==>"+o);
}
}
Java code
public class Test1 {
{
System.out.println("3");
}
// 4.父类构造器
Test1() {
System.out.println("4");
}
// 1.父类静态初始化块
static {
System.out.println("1");
}
public Element e=new Element("SupB");
public static Element es=new Element("StaticSupA");
}
Java code
public class Test2 extends Test1 {
Test2() {
System.out.println("6");
}
// 2.子类静态初始化块
static {
System.out.println("2");
}
// 5.初始化块
{
System.out.println("5");
}
public Element e=new Element("SubB");
public static Element es=new Element("StaticSubA");
public static void main(String[] args) {
// 即使newTest2实例,静态块初始化也进行
System.gc();
new Test2();
}
}