my thought is that here a is an instance variable of object a1 so when a1=null then a1.a also null
when reference variable is null then instance varaible of that particular object which is pointing to the same object is also becomes null
My understanding is that an object is eligible for garbage collection if it is "unreachable".
What does "unreachable" mean here? As a programmer I can't reach a1.a after line 3 because I'll get an NPE, so from my point of view a1.a is unreachable. So you could say both a1 and a1.a are unreachable and eligible for gc (2 objects are eligible after line 3).