Page 231 - CA_Blue( J )_Class10
P. 231
18 public static void main()
19 {
20 boolean b;
21 int n=121;
22 System.out.println("Checking "+n+ "is a palindrome or not");
23 PalindromeCheck pc = new PalindromeCheck();
24 b=pc.palin(n);
25 if(b)
26 System.out.println(n+ " is a Palindrome Number");
27 else
28 System.out.println(n+ " is not a Palindrome Number");
29 }
In the above example, palin(n) in the main() method contains the actual parameter whose copy is sent to the method
palin(int m). Since, a copy is sent, after execution of palin() method, the value of m will be reduced to 0. But, it will have
no effect on variable n in main() method. This is why, we can use the following line:
System.out.println(n+ "Palindrome Number");
Note: In pass by value, any change in the formal parameter will not reflect on the actual parameter.
Also, any type of primitive data can be used in pass by value.
10.6.2 Pass by Reference
In pass by reference, the actual parameter and the formal parameter shares the same location in the memory.
Reference means the memory location. Let us take the following example:
Program 2 To add "n" to all the numbers of array ar[] in the method increase().
1 class IncreaseArray
2 {
3 void increase (int arr[], int a)
4 {
5 int i;
6 for (i=0; i<arr.length;i++)
229
User-defined Methods 229

