Are these two declarations of String different ? I can't understand it! Could someone here help me?
This topic has been discussed before. You might want to try searching on word combos like 'new' and 'garbage'. You'll probably get a broader discussion that way. Here is just one of the many discussions: http://www.javaranch.com/ubb/Forum24/HTML/002268.html
Hope that helps,
Originally posted by Tony Sam:
[b]The String s = "hello"; s = null; is not garbage collected but String s = new String ("hello"); s = null; is garbage collected.
Are these two declarations of String different ? I can't understand it! Could someone here help me?[/B]
1)From the following code how many objects are eligible for garbage collection?
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
i think it must be D), but the correct ans is A) , why??