Lets say I have a class as below:
public class class1{
private int[] array1;
public class1(){
array1 = new int[10];
}
public int[] getArray(){
return array1;
}
}
If I create an instance of this class in another class or in main and use the getArray() method to assign the array to another variable in the upper class and then modify the values of the array there, will the original array values in the first class be modified also?
Yes it will be modified, because what you get in your caller, is not a copy of the array itself, rather you get a copy of the reference to the original array object.
And, if you modify the array using any reference, the change will be reflected for all the references pointing to the array.