Why does this work, displaying array in sorted order?:
Integer[] array={7,5,9,3,6,0,2,4};
MergeSort.mergeSort(array,0,7);
System.out.println(Arrays.toString(array));
Specifically, why does passing array to a public static void method mergeSort end up modifying the array itself? I thought that Java protected from this. For example this code:
public static void main(String[] args){
int c=2;
change(c);
System.out.print(c);
}
public static void change(int c){
c=4;
}
returns 2 instead of 4. I am confused why Java allows you to modify an array passed as a parameter, but not an int