This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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>
Joined: Sep 14, 2003
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.
Joined: Jul 02, 2002
Thank you David. Congratulations on your 100% score on the real exam!