File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question  from K&B -  pl clarify 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 "question  from K&B -  pl clarify " Watch "question  from K&B -  pl clarify " New topic

question from K&B - pl clarify

jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
This is the question from K&B of chapter 3.
class CardBoard {
Short story = 5;
CardBoard go(CardBoard cb) {
cb = null;
return cb;
public static void main(String[] args) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null;
// do Stuff
} }
When // doStuff is reached, how many objects are eligible for GC?
My thinking was the objects associated to c1 and c3 are eligible. Considering the Short wrapper object associated with each of them, there should be 4 objects eligible for GB.
Obviously, the answer is wrong. Can you explain whats wrong in my understanding please?

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
Discussed earlier


jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
Cheers mate
I agree. Here's the link:
subject: question from K&B - pl clarify
It's not a secret anymore!