Given the code fragment:
public class Test {
    static int count = 0;
    int i = 0;
    public void changeCount() {
        while (i < 5) {
            ++i;
            count++;
        }
    }
    public static void main(String[] args) {
        Test check1 = new Test();
        Test check2 = new Test();
        check1.changeCount();
        check2.changeCount();
        System.out.println(check1.count + " : " + check2.count);
    }
}
What is the result?
A.
10 : 10
B.
5 : 5
C.
5 : 10
D. Compilation fails
題解
「count」是類別(靜態)變數,就算Test類別被實體化成許多個物件,用來儲存「count」的記憶體空間也都還是一開始的那個。
check1和check2物件分別執行一次「changeCount」方法,將Test類別的「count」類別變數從0開始,加1加了10次。因此最後「count」類別變數儲存的值為10,輸出「10 : 10」。

