Source enthuware
At which line the object created at line 3 reffered by s will be garbage collected.
1)public class TestClass {
2) public static void main (
String args[]){
3) Student s = new Student("Vaishali", "930012");
4) s.grade();
5) System.out.println(s.getName());
6) s = null;
7) s = new Student("Vaishali", "930012");
8) s.grade();
9) System.out.println(s.getName());
10) s = null;
}
}
1)It will not be Garbage Collected till the end of the program.
2)Line 5
3)Line 6 Answer
4)Line 7
5)Line 10
i thought the answer is 4 ie line 7.But they saying the answer is 3 line 6.
At line 6 we are eligible that object by putting that reference to null.
By this time the garbage collector my not run.
But at line 7 s is refering to new object.
Can you give your suggestions on this ?
Thanks
Rao