Page 234 - CA_Blue( J )_Class10
P. 234
8 System.out.println("Difference of the numbers : "+d);
9 }
10 public static void main (String args[])
11 { calculator.difference(10,6);
12 calculator ob = new calculator ();
13 ob.sum(10,15);
14 }
15 }
Explanation:
In the above program, since the difference() method is a static method, so it can be called directly by using the name
of the class calculator. But, the sum() method is a non-static method, so an object set in code font or consolas has been
created.
10.8 PURE AND IMPURE METHODS
Another category of methods is pure and impure methods. This difference is based on two factors:
1. Whether the functions return or does not return a value.
2. Whether the function changes the state of an object or not.
10.8.1 Pure Method
A pure method does not change the state of an object and also returns a value to the method from where it is called.
Let us take an example:
To input the name and current salary of an employee. Suppose 10% has increased the salary
Program 3 amount for the new year. Using the function increase_sal(), print the total amount the person
will receive.
1 import java.util.*;
2 class EmployeeSalary
3 {
4 double increase_sal(double amt)
5 {
6 amt=amt+(0.1*amt);
7 return amt;
8 }
232232 Touchpad Computer Applications-X

