Congratulations Vijay!
You wrote :
2. A
Not sure, though,
Foo's implementation is unspecified, it might have passed the bar reference to some other object.
Pleas try this. I think, it will make you sure:
----------------------------------------
public class
Test {
public static void main(
String args[]) {
Foo foo = new Foo();
Bar bar = new Bar();
// foo.somemethod(bar); //please remove comments
bar = null;
foo = null;
System.gc();
System.out.println(Foo.b);
}
}
class Foo{
static Bar b;
public void somemethod(Bar b){
this.b = b;
}
}
class Bar{
public void finalize(){System.out.println("finalize");}
}