Hi All...
-------------------------------------
public class example {
int i[] = {0};
public static void main(
String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
i[0] = 2;
i[0] *= 2;
}
}
The program prints 4. Fine.
---------------------------------
But then Can anyone explain me what happening in this program???
public class example {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
int j[] = {2};
i = j;
}
}
The program prints 1. I thought i & j were referencing same object after the assignment (i=j)?
Anyone please. Thank you.