I draw diagram more than 5 times and found only 1 object eligible for collection. Please explain ..
Since you have access to, did you follow the solving technique presented by this video: http://www.examlab.org/v/garbage-collection
?
It seems
A d=new A().aob=new A();
has a tricky part
here 2 objects are created
d and new A().aob refers to same object that is declared in last
and new A() in between is eligible for gc.
If this is correct then 2 object are eligible
Am i right?
That's completely correct! That statement creates an object of A (the first new A()), and then take its aob variable, and then make it refer another object of A (the second new A()).
So we have two objects of A, and the aob of the first of these two objects refer the other object. So that makes a couple of objects, which are eligible for the garbage collector.