File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Kathy's Book- GC question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Kathy Watch "Kathy New topic
Author

Kathy's Book- GC question

Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
The following Q is from Kathy's book on SCJP1.4

After line 6 runs. how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
Answer given
10. B. By the time line 6 has run, the only object without a reference is the one generated
as a result of line 4. Remember that “Java is pass by value,” so the reference variable x is not
affected by the m1() method.

My answer is C. I completely agree with Kathy's answer and explanation given above. But what about the object created in the method m1()? Isn't that also eligible for GC as no thread can reach it?
I would like to hear from Kathy.
Thanks in advance,
Sarma
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
But what about the object created in the method m1()? Isn't that also eligible for GC as no thread can reach it?

Sarma,
Infact, thats the only object eligible for GC. According to the explanation, if you closely observe, the only object without a reference is the one generated. This object is generated in the m1() method and its reference is passed as a return reference variable to the line 4. Apart from this object , there is no new object being created at line 4
Hope this helps
Sri
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Thanks Sri. I missed that.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
Sri -
You beat us to the punch !
good job..


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Sridhar Srikanthan
Ranch Hand

Joined: Jan 08, 2003
Posts: 366
Bert,
Hope I can repeat the same performance in the final exam
Sri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Kathy's Book- GC question