/* ---------------------- classes --------------- */
public class A {
public static String str = "compile";
public A() {
}
}
public class B {
public static String str = A.str;
public B() {
}
}
/* ----------------------------------------------- */
/* ------------ main class --------------------- */
public class C {
public static void main(String[] args) {
A.str = "runtime";
A a = new A();
B b = new B();
// comment at the first, and comment this out next time
//A.str = "runtime2";
System.out.println(A.str);
System.out.println(a.str);
System.out.println(B.str);
System.out.println(b.str);
}
}
/* --------------------------------------------- */
结果是这样的......
带注释:运行时运行时运行时
不加评论:runtime2 runtime2 runtime 运行时
我理解 A 的情况,但我不理解 B 的情况。你能解释一下吗?