public class StaticTest {
public static int k = 0;
public static StaticTest s1 = new StaticTest("s1");
public static StaticTest s2 = new StaticTest("s2");
public static int i = print("i");
public static int n = 99;
public int j = print("k");
{
print("构造块");
}
static {
print("静态块");
}
public static int print(String s) {
System.out.println(++k + ":" + s + "\ti=" + i + "\tn=" + n);
++n;
return ++i;
}
public StaticTest(String s) {
System.out.println(++k + ":" + s + "\ti=" + i + "\tn=" + n);
++i;
++n;
}
public static void main(String[] args) {
new StaticTest("init");
}
}
-----------------运行结果------
1:k i=0 n=0
2:构造块 i=1 n=1
3:s1 i=2 n=2
4:k i=3 n=3
5:构造块 i=4 n=4
6:s2 i=5 n=5
7:i i=6 n=6
8:静态块 i=7 n=99
9:k i=8 n=100
10:构造块 i=9 n=101
11:init i=10 n=102