It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collector" Watch "Garbage collector" New topic

Garbage collector

tushar parab

Joined: Feb 11, 2009
Posts: 5
following is the code snippet from Cathy Siera SCJP book.


When // doStuff is reached, how many objects are eligible for GC?
A. 0
B. 1
C. 2
D. Compilation fails
E. It is not possible to know
F. An exception is thrown at runtime.

The answer for above code is C. Author says only two objects are eligible. Object c1 and Story object associated with it.
Can anyone please explain why answer is 2. Why only 2 objects are eligible for garbage collection and why Cardboard c3 is not eligible for garbage collection?
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1599
She's Kathy not Cathy.

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
This question has been discussed many times here. Use the Search function to find these.

I agree. Here's the link:
subject: Garbage collector
It's not a secret anymore!