public class Test01 {
public static void main(String[] args) throws Exception {
Test01 t1 = new Test01();
InnerTest01 t = new InnerTest01();
InnerTest02 t2 = new InnerTest02();
InnerTest03 innerTest03 = t1.new InnerTest03();
}
static {
System.out.println("Test01 static 01");
}
private static class InnerTest01 {
static {
System.out.println("InnerTest01 static 01");
}
public InnerTest01() {
System.out.println("InnerTest01 构造方法!");
}
static {
System.out.println("InnerTest01 static 02");
}
}
static {
System.out.println("Test01 static 02");
}
private static class InnerTest02 {
public InnerTest02() {
System.out.println("InnerTest02 构造方法!");
}
static {
System.out.println("InnerTest02 static 01");
}
}
private class InnerTest03 {
public InnerTest03() {
System.out.println("InnerTest03 构造方法!");
}
// 异常代码
/*
* static { System.out.println("InnerTest03 static 01"); }
*/
}
static {
System.out.println("Test01 static 03");
}
}
Test01 static 01
Test01 static 02
Test01 static 03
InnerTest01 static 01
InnerTest01 static 02
InnerTest01 构造方法!
InnerTest02 static 01
InnerTest02 构造方法!
InnerTest03 构造方法!