So this is my code:
File A.java
package test;
import java.util.Arrays;
public class A {
static int[] test;
public static void main(String... args) {
test = new int[2];
B.function(test);
System.out.println(Arrays.toString(test));
}
}
File B.java
package test;
public class B {
static int[] function(int[] array){
array[0] = 1;
array[1] = 2;
return array;
}
}
Output: [1,2]
I am not able to understand how exactly does this of code works. I am passing a variable called "test" to a function whose parameter is int[], and parameters are treated as local variables, as far as my understanding goes. So how does a change made to a local variable reflect in the actually passed variable?