15. s1.a1.a2.a2=new A();
17. s1.a2.a1.a2=null;
is both are same?In this questions only one object dont have reference ie s1.a2.a1.a2=null how the output is 2 ?
The two statements do not represent or refer the same object.
As you set the s1.a2.a1.a2 reference to null, it isolates two objects, one that has been referred by that reference, and the object that has been referred by the 'a2' of that object.
Since you have access to our videos, have you watched our garbage collection video?