This question is from Javacaps mock 1 Q12 Here the answer given is A but since according to our final discussion string literals are not garbage collected then the answer should be D. Am i right?
String string1 = "Test"; String string2 = "Today"; string1 = null; string1 = string2; A) 1 B) 2 C) 3 D) 0 another question no 11 A) The garbage collector runs in low memory situations B) You can run the garbage collector when ever you want. C) When it runs, it releases the memory allocated by an object, which is no more in use. D) Garbage collector immediately runs when you set the references to null. Ans given is A and C but i feel it should be only C Please someone help Neha
nss
Nain Hwu
Ranch Hand
Joined: Sep 16, 2001
Posts: 139
posted
0
Neha, I agree with you 100%.
Fei Ng
Ranch Hand
Joined: Aug 26, 2000
Posts: 1241
posted
0
I agree on the first one.. but the second one.. the GC does A) The garbage collector runs in low memory situations so it is A and C. correct me if i am wrong.
Neha Sawant
Ranch Hand
Joined: Oct 11, 2001
Posts: 204
posted
0
But FEING you cannot be sure when GC occurs so you cannot make a conclusion like the one mentioned Correct me if i am wrong Regards Neha
vishal avad
Ranch Hand
Joined: Nov 29, 2001
Posts: 45
posted
0
hi neha u can not sure when GC is going to run but its true that it runs in low memory situations. but it is not sure that whether it able to free up the memory or not i m agree on 1.