001package bradleyross.demonstrations;
002/**
003 * Some demonstrations of the results of passing objects in
004 *    the parameter lists of methods.
005 * @author Bradley Ross
006 *
007 */
008public class ArrayDemos implements Runnable {
009        int[] a = new int[]{0, 1, 2, 3, 4, 5};
010        public void run() {
011                int[] array = a.clone();
012                System.out.println("Value of element 2 before call to changeElement is " + Integer.toString(array[2]));
013                changeElement(array, 2, 6);
014                System.out.println("Value of element 2 after call to changeElement is " + Integer.toString(array[2]));
015                int a = 24;
016                System.out.println("Value before call to changeValue is " + Integer.toString(a));
017                changeValue(a, 10);
018                System.out.println("Value after call to changeValue is " + Integer.toString(a));
019        }
020        private void changeValue(int a, int newValue) {
021                System.out.println("changeValue: starting value is " + Integer.toString(a));
022                a = newValue;
023                System.out.println("changeValue: final value is " + Integer.toString(a));
024        }
025        private void changeElement(int[] array, int position, int newValue) {
026                array[position] = newValue;
027                System.out.println("Within method changeElement position " + Integer.toString(position) + 
028                                " changed to " + Integer.toString(newValue));
029        }
030        public static void main(String[] args) {
031                System.out.println("Starting program");
032                ArrayDemos instance = new ArrayDemos();
033                instance.run();
034        }
035}