Page 235 - CA_Blue( J )_Class10
P. 235
9 public static void main ()
10 {
11 Scanner sc= new Scanner (System.in);
12 double sal,in_sal=0.0;
13 String name;
14 System.out.println("Enter name and salary:");
15 name=sc.nextLine();
16 sal=sc.nextDouble();
17 System.out.println("Before calling increase_sal()");
18 System.out.println(name+ " " + sal);
19 EmployeeSalary employee1 = new EmployeeSalary();
20 in_sal=employee1.increase_sal(sal);
21 System.out.println("After calling increase_sal()");
22 System.out.println(name+ " " + sal);
23 System.out.println("Increased Salary " + in_sal);
24 }
25 }
Explanation: Here, the "sal" variable does not change after the "increase_sal(double)" method is called. Also, the
method is returning a value to "in_sal" variable. Thus, we can say that the increase_sal(double) method is a pure
method.
10.8.2 Impure Method
An impure method changes the state of an object. If the variable in the formal parameter changes its value, then the
variable of the actual parameter also changes. Also, the method may or may not return a value to the method from
where it is called. An impure method is also called a mutator.
233
User-defined Methods 233

