JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
29 / 64
At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
ABefore statement labeled 1
BBefore statement labeled 2
CBefore statement labeled 3
DBefore statement labeled 4
ENever
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
Before the statement labelled 4, the object s becomes available and eligible for garbage collection. The garbage collection activity is done by the garbage collector thread, whose work is to sweep out abandoned objects, or the objects which do not have any live reference anymore. The garbage collector thread comes once in a while in the heap area, and when it finds any abandoned objects, it sweeps out the abandoned objects after calling the finalize() method on that object.
Read Full Answer
Report Error
Please Login First Click Here