×

Loading...

Can u explain the following codes for me more detailly?

public class example {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
//When the code is executed,first this change_i's i[] points to the i[] which is declared and instanciated in main(), then the main call the routine change_i,after executing "i=j" in it ,the i(a local variable of change_i routine) point to j,in the meantime ,there are two array instance in the memory,so it has no relation with "i" that is declared in main()
//anser is c,the output is 1
System.out.println(i[0]);
}
public static void change_i(int i[]) {
int j[] = {2}; //"j[]"'s visibility is local
i = j; //"i" points to "j"
}
}


A. The program does not compile.
B. The program prints 0.
C. The program prints 1. (right)
D. The program prints 2.
E. The program prints 4.
Report