Hi,
c1 is null ..this is very explicit.
c3 is also null since the object reference returned by the method 'go' is null;
C2 is pointing to a object on the heap. So C2 is not available for GC.
So only c1 and c3 are available for GC.
You may get confused as to how c2 is not null since it is passed as an argument to the method 'go' which sets it to null.
It must be understood that c2 is a reference to an object and not the actual object itself.
Also in
java it is always pass by 'value' ..
So when pass c2 as the parameter to the 'go' method, the jvm creates a copy of 'c2' and passes it to the 'go' method.
c2 -> {some object on the heap }
jvm creates a copy of c2 ..and names it cb.
so cb is also pointing to the same object that c2 was pointing to..
inside the method you are doing 'cb = null ' which affects cb only and not c2 .
c2 continues to point to the same object as it was earlier.
so except for c2 other references are null which means they are not pointing to any object and hence eligible for garbage collection.