aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method returns what happens to garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method returns what happens to garbage collection" Watch "method returns what happens to garbage collection" New topic
Author

method returns what happens to garbage collection

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Following code is from OCP Practice Exam book. It says





D. Four objects are eligible for garbage collection.



How the answer is changed in folowing case




dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Not all of us carry our K&B books around all day. ;) So give us the full question please. Then, tell us what YOU think will happen if the code is changed as you suggest.
Jeffrey Tian
Ranch Hand

Joined: Jun 02, 2010
Posts: 34
I has doubt on this question:

On Line 15. a3.password = a1.acctNum.longValue();
an object is created. The total number of objects should be 5. Am I right?
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Here is Complete question :



When line 8 is reached, which are true? (Choose all that apply.)
A. a1.acctNum == a3.password
B. a1.password == a2.password
C. Three objects are eligible for garbage collection.
D. Four objects are eligible for garbage collection.
E. Six objects are eligible for garbage collection.
F. Less than three objects are eligible for garbage collection.
G. More than six objects are eligible for garbage collection.

Correct Ans : D


Now follow :
As if change is made in Banker class


As with my understanding None of the object is eligible for GC since ob still hold the reference to the object(s).
Jeffrey Tian
Ranch Hand

Joined: Jun 02, 2010
Posts: 34
Looks like all of us didn't Google this questions. This question has been discussed a lot in this forum. Click Here

I have another concern on answer B. The book says: B is correct, although when line 8 is reached, the references are lost.
Both references have gone, how can we compare them?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: method returns what happens to garbage collection