wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MIndQ #36 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 "MIndQ #36" Watch "MIndQ #36" New topic
Author

MIndQ #36

mary lee
Greenhorn

Joined: Apr 03, 2001
Posts: 8
look at this question:
36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
the answer is 1
but I think should be 2, there are three String objects "Nick"
"Jason" and "Frieda", at line A only "Frieda" is still referrenced by newestName , other two are not referrenced any more
is it right?
could anyone help? the garbage collection always make me confused
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
hi mary
i think ur right ..
2 must be correct ans
always draw diagrams whenever the object is created
and one box for a variable and make it point to
respectove obj..
so u wouldn't get confused..
i also got confused in Exam and missed the question.
Bhupendra


<B>Bhupendra Mahajan</B>
g krishnan
Greenhorn

Joined: Mar 30, 2001
Posts: 23
guys,
i had drawn the diagram and found only "Nick" is not pointed by any of the references, so i think 1 is correct
thanx
Vidya Krishnamurthy
Greenhorn

Joined: Mar 27, 2001
Posts: 15
I think the right answer is 1. the only object that is eligible for garbage collection is "Nick". "Jason" is referred by new name at line A.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Jason is referenced by newName
Frieda is referenced by newestName
Nick isn't referenced at all
So only 1 object is eligible
Hope that helps,
Bill
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Wait a min
<pre>
Nick Jason Frieda
newName - -
- newName -
- newName name
- - name,newName
- - newName
</pre>
so i thoink 2 is correct ans
Bhupendra
[This message has been edited by Mahajan Bhupendra (edited April 03, 2001).]
Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
Mahajan -
Bill is correct, as Nick is the only object without a reference. In your diagram you are pointing "Frieda" to newName, when it should be pointing to newestName.
Hope that helps -
Chris

[This message has been edited by Chris Cingrani (edited April 03, 2001).]
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Chris
Soory i m very soory..
i got confused between newName and newestName..
1 is correct ans..
soory to all
Bhupendra

[This message has been edited by Mahajan Bhupendra (edited April 04, 2001).]
mary lee
Greenhorn

Joined: Apr 03, 2001
Posts: 8
yes
I did not notice the newname and newestname are different
a careless mistake
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MIndQ #36
 
Similar Threads
MindQ question 36 garbage collection
garbage collection question
Garbage Collection????
gc ??
garbage collection