Page 232 - CA_Blue( J )_Class10
P. 232
7 {
8 arr[i]=arr[i]+a;
9 }
10 System.out.println();
11 System.out.println("Result after increase by "+a+ " in increase()");
12 for (i=0; i<arr.length;i++)
13 {
14 System.out.print(arr[i]+ " ");
15 }
16 }
17
18 public static void main ()
19 {
20 int ar[]={1,2,3,4,5};
21 System.out.println("Original array in main ():");
22 for (int i=0; i<ar.length;i++)
23 {
24 System.out.print(ar[i]+ " ");
25 }
26 IncreaseArray obj = new IncreaseArray ();
27 obj.increase(ar,10);
28 System.out.println();
29 System.out.println("Original array in main () after calling"
30 +"increase():");
31 for (int i=0; i<ar.length;i++)
32 {
33 System.out.print(ar[i]+ " ");
34 }
35 }}
In the above example, after the method increase(ar,10) is called, the arr[] items are increased by 10. And after that,
when the control reaches the main() method, we see the changed values are printed. Thus, we can see that both the
array ar[] and arr[] have the same value after executing the increase() method, and therefore, we can say that ar[] and
arr[] are different names or aliases given to the array in the same memory location.
230230 Touchpad Computer Applications-X

