/* ---------------------- 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さんの場合はわかりません。これについて説明していただけますか?