Hi,
im Buch vom SCJP steht im Kapitel 3 folgende Frage mit Antowrt.
11. Given:
When line 16 is reached, how many objects will be eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
Answer:
® ✓ B is correct. It should be clear that there is still a reference to the object referred to by
a2, and that there is still a reference to the object referred to by a2.b2. What might be
less clear is that you can still access the other Beta object through the static variable
a2.b1—because it's static.
®˚ A, C, D, E, and F are incorrect based on the above. (Objective 7.4)
Laut meiner Meinung und auch nachdem was in der Antwort meiner meinung steht, müssten doch eigentlich 3 Objekte noch da sein. Also Antwort D richtig sein. Was meint ihr? Lese ich es falsch oder hat sich da ein fehler eingeschlichen?
im Buch vom SCJP steht im Kapitel 3 folgende Frage mit Antowrt.
11. Given:
Java:
class Beta { }
class Alpha {
static Beta b1;
Beta b2;
}
public class Tester {
public static void main(String[] args) {
Beta b1 = new Beta(); Beta b2 = new Beta();
Alpha a1 = new Alpha(); Alpha a2 = new Alpha();
a1.b1 = b1;
a1.b2 = b1;
a2.b2 = b2;
a1 = null; b1 = null; b2 = null;
// do stuff
}
}
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5
Answer:
® ✓ B is correct. It should be clear that there is still a reference to the object referred to by
a2, and that there is still a reference to the object referred to by a2.b2. What might be
less clear is that you can still access the other Beta object through the static variable
a2.b1—because it's static.
®˚ A, C, D, E, and F are incorrect based on the above. (Objective 7.4)
Laut meiner Meinung und auch nachdem was in der Antwort meiner meinung steht, müssten doch eigentlich 3 Objekte noch da sein. Also Antwort D richtig sein. Was meint ihr? Lese ich es falsch oder hat sich da ein fehler eingeschlichen?