Src:http://devesh2k1.googlepages.com/home
How many objects will be eligible for GC just after the method returns?
public void compute(Object p)
{
Object a = new Object();
int x = 100;
String str = "abc";
}
Answer: 1
Explanation: Objects passed to the method are never garbage collected in (or right after) that method. So p cannot be GCed. x is not an object. "abc" is a string literal which goes to the string pool and is not GCed. So, only a is eligible for GC.
-----------
what about the String. Str is also garbage collected, so answer should be 2.
[ May 09, 2008: Message edited by: Jesper Young ]