Here in class J when the method m1 is called with array reference a1, is'nt the change reflected in the main method? if so, then all the objects created would be eligible for GC
but the answer says that no object will be garbage collected as only the variable a1 in the methos m1 is set to null and the change is not going to affect the a1 in the main method.
my question is when passing an array reference var to a method, is the change in that method reflected ??
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);
for (int i = 0; i < a1.length; i++) {
System.out.print(a1[i]);
}}}