public class Test { static int a=1; static { new InnerStaticClass(); } static int b=2; static { System.out.println("b="+b); } static class InnerStaticClass{ InnerStaticClass(){ System.out.println("a="+a); System.out.println("b="+b); } } public static void main(String[] args) { new Test(); } } 得到输出的结果是: a=1 b=0 b=2
public class Test {
static int a;
static int b;
static {
a = 1;
new InnerStaticClass();
b = 2;
System.out.println("b="+b);
}
static class InnerStaticClass{
InnerStaticClass(){
System.out.println("a="+a);
System.out.println("b="+b);
}
}
public static void main(String[] args) {
new Test();
}
}