Question: When the processing of line 2 begins, how many objects of type Q that were created at line 1 are eligible for garbage collection? Answer: 9 Is it possible that before the for loop ends, some of the object of type Q have already garbage collected so when System.gc() is invoked the number of objects of type Q left are less than 9?
Kristof Camelbeke
Ranch Hand
Joined: Nov 28, 2001
Posts: 97
posted
0
In my opinion I don't think so because you can only make objects eligible for GC in these cases : 1) Nulling a Reference (q1 = null; ) 2) Reassigning a ref. variable (q1 = q2); 3) Isolating a ref.
David Hadiprijanto
Ranch Hand
Joined: Sep 14, 2003
Posts: 52
posted
0
Hi Yosi, I think you are right that some of the 9 objects created in line 1 might have been garbage collected before the loop ends. But for the sake of the exam, I think the answer is indeed 9. The SCJP exam expects us to know when such objects are eligible for GC, not when they are actually garbage collected. The keyword here is eligible. So, I think the wording in Dan's exam is already correct, and the answer is 9. Just my 2 cents.
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
posted
0
Yosi, If I remember correctly, the real exam uses the words "are eligible". It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected. The next version of my exam will use the more correct wording. Does anyone object to the new version?
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
David Hadiprijanto
Ranch Hand
Joined: Sep 14, 2003
Posts: 52
posted
0
It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected.
Sounds like a better ambiguity-eliminator to me. Dan, I admire your commitment to provide high quality SCJP mock exam.
Dan Chisholm
Ranch Hand
Joined: Jul 02, 2002
Posts: 1865
posted
0
Thank you David. Congratulations on your 100% score on the real exam!