A good answer might be:

  1. Did the two arrays have to contain the same number of elements?
    • NO---the method will work for any length of array.
  2. Did the two arrays both have to be arrays of int?
    • YES---the parameter says to expect an array of int

Picture of the Action

Here is a picture that shows what the executing program looks like just after the first call to the print method.

Several points:

  1. ArrayDemo is shown in dotted lines because it is a class definition, not an object.
  2. ArrayDemo's static method main() is being used.
  3. The variables ar1 and ar2 refer to two array objects.
  4. The variable operate refers to an ArrayOps object.
  5. The picture shows what happens when the print() method of operate is called with ar1 as a parameter.
  6. Just after the call, the formal parameter x refers to the same object as does to variable ar1 .

Usually you do not think about things in such excruciating detail. You would think "call a method to print the array" and would write

    operate.print( ar1 ); 

But sometimes you really need to know what is going on.


QUESTION 5:

Does the picture change when the second array is printed?

Click Here after you have answered the question