Pass as argument - a copy of the reference to the instantiated array is passed to the method. This means that any changes made to the array elements inside the method are persistent. The one exception to this is if you assign the argument to reference a different array in memory.
public static void main(String[] args) {
Person alpha = new Person("Elsa", 100);
Person beta = new Person("Anna", 200);
Person[] one = new Person[2];
one[0] = alpha;
one[1] = beta;
Person[] two = one;
two[1].setName("Miranda");
System.out.println(one[1].getName());
}
public static void main(String[] args) {
Person alpha = new Person("Elsa", 100);
Person beta = new Person("Anna", 200);
Person[] one = new Person[2];
one[0] = alpha;
one[1] = beta;
Person[] three = new Person[2];
for (int i = 0; i < 2; i++)
three[i] = one[i];
one[0].setId(999);
System.out.println(three[0].getId());
}
public static void main(String[] args) {
Person alpha = new Person("Elsa", 100);
Person beta = new Person("Anna", 200);
Person[] one = new Person[2];
one[0] = alpha;
one[1] = beta;
Person[] four = new Person[2];
for (int j = 0; j < 2; j++)
four[j] = new Person(one[j].getName(), one[j].getId());
four[0].setId(567);
System.out.println(one[0].getId());
}