Given:



public class MarkList {

    int num;

    public static void graceMarks(MarkList obj4) {
        obj4.num += 10;
    }

    public static void main(String[] args) {
        MarkList obj1 = new MarkList();
        MarkList obj2 = obj1;
        MarkList obj3 = null;
        obj2.num = 60;
        graceMarks(obj2);
    }
}

How many MarkList instances are created in memory at runtime?

A. 1
B. 2
C. 3
D. 4

題解

要實體化出一個物件,通常都是使用new運算子,這邊只需要算算看new的數量即可。由於程式只有在第10行使用到new運算子,因此MarkList物件只有被實體化出來一個。