This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage from MindQ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage from MindQ" Watch "Garbage from MindQ" New topic
Author

Garbage from MindQ

MONZY THARIAN
Ranch Hand

Joined: Feb 21, 2001
Posts: 63
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
a) 0
b) 1
c) 2
d) 3
e) 4

The Answer b .
Can any one explain me how . This takes a lot of time...
Cheers

Think Big . So shall you become big.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
In my opinion the answer is '0' because all are string literals here and String literals are not garbage collected.
Do correct me if I am wrong.
Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
Hi,
I think too that the correct answer is 0.
Only to be sure, check if these are all the lines, sometimes there is one GC object, and this is the one that executes the code.
..Cristian
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Answer is definitely 0. For the n-th time, String literals are NOT garbage collected
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
sridevi kumar
Ranch Hand

Joined: Oct 17, 2001
Posts: 31
This contradicts with javaprepare.com tutorial "Classes in Java":
public class GCTest {
public static void main(String args[]) {
String a,b;
String c = "test";
a = c;
c = null; // The String "test" is not yet
//available for GC as a still points to "test"
b = new String("xyz");
b = c; // String "xyz" is now available for GC.
a = null;
//String "test" is now available for GC.
}
This explanation with yours confuses me. Could someone explain the correct procedure in detail?
}
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Originally posted by Valentin Crettaz:
Answer is definitely 0. For the n-th time, [b]String literals are NOT garbage collected
HIH
[/B]

Im confused too.
String literals never get collected by the GC Thread, but y question is : are they "elegible" ???
Im agree with you Valentin, but Im a little confused about the reason why String literals are never collected...
:/
----
Ive just read the topic:
Topic: Are string literals garbage collected?
And I have it clear now
Thanks
[This message has been edited by Zkr Ryz (edited November 23, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage from MindQ
 
Similar Threads
Garbage Collection????
MindQ q#36
garbage collection
doubt on garbage collection
garbage collection question