Assuming that line 19 is the line marked by TODO Auto-generated method stub
, then of the objects created by the program the only object which is eligible for GC by line 19 is the object referred to by the variable a1.
The object which was originally assigned to a2 is still assigned, so it's not available.
The static value in A.b1 is still assigned to the object which was originally assigned to b1 so that object is not available for GC - static values live for the lifetime of the class so even though instance a1 may get GC'd the static instance which was assigned through it can still be referenced.
Because instance a2 is still assigned, the instance field a2.b2 is also unavailable for GC. This value holds the instance of B originally assigned to local variable b2 in the main method.
Of the four objects created in the main method the only one actually available for GC by the final line of the program is the object initially assigned to a1. It's only reference has been set to null and so nothing the instance is not reachable anymore. All other instances are reachable either via a local variable (a2), a static reference (A.b1) or an instance reference (a2.b2).