Give the following code:
class A {
Boolean b;
A easyMethod(A a){
a = null;
return a;
}
public static void main(String [] args
Your question is quite confused.
The garbage collector works on objects, not on variables. So when you say that a2 is eligible for GC it mean nothing. You should say the object referenced by a2 at line N is eligible for GC at the line N+M.
In your example you only have 3 objects being instantiated. It is the first create A and the last create A instance that are eligible for GC.