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

Given:

interface Animal {
void makeNoise();
}

class Horse implements Animal {
Long weight = 1200L;

public void makeNoise() {
System.out.println(“whinny”);
}
}

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

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

Given:

interface Animal {
void makeNoise();
}

class Horse implements Animal {
Long weight = 1200L;

public void makeNoise() {
System.out.println(“whinny”);
}
}

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

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

A.
0

B.
1

C.
2

D.
3

E.
4

F.
6

Explanation:



Leave a Reply 3

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


Harry

Harry

E

sana

sana

how four objects?can u explain please

jmc

jmc

There are two Icelandic class for GC. each of the Icelandic has ‘this’ object plus the ‘Long weight’ object.