More Array Details: Pass By Reference, Pass By Value

Note:  Please keep the programs that you create today, in case you have a dispute about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save their own, individual copy

 

Part  2: Arrays are passed 'by reference': Try This Out!

 

            Grab one of the files that you've been working with for the past couple of lectures, that deals with arrays.  Pick one that has a PrintArray method in it.

 

            Copy the PrintArray method, and rename it to ZeroArray.  This method will set each element of the array to be 'zero', thus returning it to the same state that the array started in, when Java first created it.

            Next, create (or use an array that's already been created) in main – put some values into the array, and call PrintArray, so you can see what's in the array.  Then call ZeroArray, and then call PrintArray again, in order to confirm that the array has, in fact, been zero'd out by the ZeroArray method.

 

Part  3: Primitives are passed 'by value': Try This Out!

 

            Grab one of the files that you've been working with for the past couple of lectures, that deals with arrays.  Pick one that has a PrintArray method in it.

            try to create a method called ZeroInteger, which takes as a parameter a single int, and assigns the value zero to it.  In main, create an integer & give it a value (say, 7), print out the integer, then call ZeroInteger on it, and then print the integer again.  Notice that the value of the integer in main doesn't change, since we're making a COPY of the value, not passing a reference to the original integer.