operate.findMax( ar2 )
Here a picture that shows the situation just after
the second method call:
operate.print( ar2 );
x
of the method
now refers to the second array.
By using parameters with methods you can use the same method with different data. This makes the method into a useful tool that can be used in many situations.
Note: In this picture, the arrow connected to ar2
and the arrow connected to x
look quite different,
although they point to the same object.
However, when the program is running, the reference in
x
is identical to the reference in
ar2
.
Both contain an identical reference to the array object.
(Review Question:) The findMax(int[] x)
method uses a
parameter that refers to an object.
Can parameters also be primitive types, like int
?