public class Demo {
public static int k = 0;
public static Demo t1 = new Demo("t1");
public static Demo t2 = new Demo("t2");
public static int i = print("i");
public static int j = print("j");
public static int n = 99;
{
print("construtor code");
}
static {
print("static code");
}
public static int print(String s) {
System.out.println("i=" + i + "," + s + ",k=" + k + ",n=" + n + ",j=" + j);
++i;
++k;
++n;
return i;
}
public Demo(String string) {
print(string);
}
public static void main(String[] args) {
byte b = 3 + 4;
Demo d = new Demo("T");
}
}
把这个题给弄懂了,那对变量的加载顺序就完全没问题了.
java基础-变量的加载
最新推荐文章于 2024-01-31 20:21:59 发布