Q29 from javaprepare.com 29.At what stage in the following method does the string "abc" becomes available for garbage collection. Select the one correct answer.
A.Before statement labelled 1 B.Before statement labelled 2 C.Before statement labelled 3 D.Before statement labelled 4 E.Never. The answer is D. Should it not be C ? i.e. Before stmt 3.
void method X() { String r = new String("abc"); String s = "abc"; r = r+1; //1 r = null; //2 s = s + r; //3 } //4 Hi ankur which String u r talking about is the String present in Heap memory that was created using statement String r = new String("abc"); Well if this is the string u r expecting it would be eligible for garabage collection at anytime after line marked with //1 is executed. if u r talking about the String created in the String pool with String s = "abc" ..Then it would be available for garbage collection only after class in which this method is declared is unloaded.
I need a new interior decorator. This tiny ad just painted every room in my house purple.