Page 233 - CA_Blue( J )_Class10
P. 233
Note: In pass by reference, any change in the formal parameter will also reflect on the actual
parameter. Also, only non-primitive data can be used in pass by reference.
10.6.3 Difference Between Pass by Value and Pass by Reference
Pass by Value Pass by Reference
The copy of the actual parameters is sent to the formal The actual parameters and the formal parameters share
parameter. the same location in the memory.
Any change in the formal parameter will not reflect on Any change in the formal parameter while the method is
the actual parameter. executing, the actual parameter is also changed.
Only primitive data can be used. Only non-primitive data can be used.
10.7 THE STATIC AND NON-STATIC METHODS
If the word static is used before any method, then it means that the method directly belongs to the class and not to
its instance. This means that only one copy of the method is created, which is used throughout the program. Java
supports both static and non-static methods.
A static method is common to all the objects in the class. It can be called by its class name also. The word static is
written before the method name. For example,
public static void display()
{
System.out.println("This is static method");
}
A non-static method is also known as instance method. The word static in not written before the method name. For
example,
public void display()
{
System.out.println("This is non-static method");
}
Let us take the following example:
1 class calculator
2 { public void sum(int a, int b)
3 { int c= a + b;
4 System.out.println("Sum of the numbers : "+c);
5 }
6 public static void difference (int a, int b)
7 { int d= a - b;
231
User-defined Methods 231

