This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Barry Boones Exam Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Barry Boones Exam Doubt" Watch "Barry Boones Exam Doubt" New topic

Barry Boones Exam Doubt

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Question 13: There are a number of labels in the source code below. These are labeled a through j. Which label identifies the earliest point where, after that line has executed, the object referred to by the variable first may be garbage collected?

Select the one right answer.

a.d: (What The Awnser Is)
e.j: (what I think)

Can anyone explain me why ,i have read the explaination given by Boone but couldnt get it.

i think its last line j: becuase although variable first is nulled at line d: but its refernce is still holded by line c: by the variable riddle.

With Regds,

Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
riddle holds a new String (immutable) object = "When is a <arg0>", riddle does'nt hold a reference to "When is a " and a reference to first.

riddle = "When is a " + first
is equivalent to
riddle = "When is a ".concat(first), which creates a new String.

There's no more reference to the String created at (a) after first=null.
[ October 03, 2005: Message edited by: Seb Mathe ]

Regards,<br />Seb<br /> <br />SCJP 1.4
I agree. Here's the link:
subject: Barry Boones Exam Doubt
Similar Threads
Mock Quesion on Garbage Collection
Garbage Collection
Garbage Collection-Strings
Garbage Collection
What is this riddle?