class I {
private String name;
public void finalize() {System.out.print(name);}
public I(String s) {name = s;}
}
class J {
private static void m1(I[] a1) {
a1[0] = a1[1] = a1[2] = null;
}
public static void main (String[] args) {
I[] a1 = new I[3]; // 1
a1[0] = new I("A"); // 2
a1[1] = new I("B"); // 3
a1[2] = new I("C"); // 4
m1(a1); //5
System.gc();
}
}
in this after line //5 there are three objects created at //2,3,4
objects eligible for garbage collection
while in the below question
class I {
private String name;
public String toString() {return name;}
public I(String s) {name = s;}
}
class J {
private static void m1(I[] a1) {
a1 = null;
}
public static void main (String[] args) {
I[] a1 = new I[3]; // 1
a1[0] = new I("A"); // 2
a1[1] = new I("B"); // 3
a1[2] = new I("C"); // 4
m1(a1); //5
for (int i = 0; i < a1.length; i++) {
System.out.print(a1[i]);
}
}
}
in this no object is elligible for garbage collection after //5pls explain me