aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes again on GC 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 "again on GC" Watch "again on GC" New topic
Author

again on GC

sheri
Ranch Hand

Joined: Sep 14, 2000
Posts: 43
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
a) 0
b) 1
c) 2
d) 3
e) 4
please explain
thanks
sherin
raghurajput
Greenhorn

Joined: Sep 03, 2000
Posts: 7
How many objects are eligible for garbage collection once execution has reached the line labeled Line
A?
String name;
String newName = "Nick"; //newName points to "Nick"
newName = "Jason"; //now newname points to Jason, so Nick is eligible for garbage collection, our count=1;
name = "Frieda"; //name points to "Frieda"
String newestName = name; //newestname refers to name, hence "object" "Freida" is refered to by two variables.
name = null; // here you set name=null, but still newestname points to "Freida", so our count is still 1
//Line A
a) 0
b) 1 //ANS
c) 2
d) 3
e) 4

[This message has been edited by raghurajput (edited September 14, 2000).]
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Sheri,
Look at this page:
http://www.javaranch.com/ubb/Forum24/HTML/003438.html
Hope it helps.
Stephanie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: again on GC