When line 15 is reached, how many objects are eligible for the garbage collector?

Given:

03. interface Animal { void makeNoise(); }
04. class Horse implements Animal {
05. Long weight = 1200L;
06. public void makeNoise() { System.out.println(“whinny”); }
07. }
08. public class Icelandic extends Horse {
09. public void makeNoise() { System.out.println(“vinny”); }
10. public static void main(String[] args) {
11. Icelandic i1 = new Icelandic();
12. Icelandic i2 = new Icelandic();
13. Icelandic i3 = new Icelandic();
14. i3 = i1; i1 = i2; i2 = null; i3 = i1;
15. }
16. }

When line 15 is reached, how many objects are eligible for the garbage collector?

Given:

03. interface Animal { void makeNoise(); }
04. class Horse implements Animal {
05. Long weight = 1200L;
06. public void makeNoise() { System.out.println(“whinny”); }
07. }
08. public class Icelandic extends Horse {
09. public void makeNoise() { System.out.println(“vinny”); }
10. public static void main(String[] args) {
11. Icelandic i1 = new Icelandic();
12. Icelandic i2 = new Icelandic();
13. Icelandic i3 = new Icelandic();
14. i3 = i1; i1 = i2; i2 = null; i3 = i1;
15. }
16. }

When line 15 is reached, how many objects are eligible for the garbage collector?

A.
0

B.
1

C.
2

D.
3

E.
4

F.
6



Leave a Reply 0

Your email address will not be published. Required fields are marked *