After performance of what line, only one object will be available for the garbage collection (Garbage Collection)?

01. public class Test {
02.      Test ags = null;
03.      public static void main(String argv[]) {
04.           Test a1 = new Test();
05.           Test a2 = new Test();
06.           Test a3 = new Test();
07.           a1.ags = new Test();
08.           a2.ags = a1.ags;
09.           a3.ags = a2.ags;
10.           a1 = null;
11.           a2 = null;
12.           a3 = null;
13.      }
14. }
Explanation
After the 9th line: a1.ags, a2.ags, a3.ags point to the object created in line 7. In the 10th line of the link a1 the meaning is set to null. Now to the object created in line 4 there're no references. I.e., it becomes available to the collector. His field ags is not taken into account, since the object to which it refers, will be available via links a2.ags, a3.ags

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести