/* ---------------------- 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);
}
}
/* --------------------------------------------- */
results is like this....
with comment : runtime runtime runtime runtime
without comment : runtime2 runtime2 runtime runtime
I understand in A's case, but i don't in B's case. Would you please explain about this?