After which line the object initially refered by str is eligible for garbage collection?Select one correct answer.
1 class Garbage
2 {
3 public static void main(
String arg[])
4 {
5 String str=new String("Hello");
6 String str1=str;
7 str=new String("Hi");
8 str1=new String("Hello Again");
9 return;
10 }
11 }
My answer for this is "After line no. 8 ". Is this correct ?? If not please say what the correct answer is and the explanation.
I was searching thru the post to see if this question was already asked, but couldn't find one. In the process of searching found some articles on String and it is different than other object with respect to GC, can anyone explain it again..
Thanks,
JP