Hi All,
I Got the following question from JavaCaps Mock Exam.
12. From the following code how many objects are garbage collected?
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
A) 1
B) 2
C) 3
D) 0
The given answer is A.
But I think this answer is wrong &
answer should be D.Because In the code it'll create two string objects & they'll be placed in the
String Pool .So the objects in the string pool will not be (never) garbage collected even if you have asign the reference to the
null.
Correct me if I'm Wrong...
Thanks In advance,
Shan.