Page 268 - CA_Blue( J )_Class10
P. 268
15 {
16 f=f*i;
17 }
18 System.out.println("Factorial: "+f);
19 }
20 }
Explanation: Here, f and i variables in the display () method are local variables as the scope of the variables exists
within the method.
11.5.3 Member Methods
A method that is declared within the class is called a member method. It can be declared public or private. For example:
1 import java.util.*;
2 class sum
3 {
4 int a,b,s;
5 void input()
6 {
7 Scanner sc= new Scanner(System.in);
8 System.out.println("Enter two numbers" );
9 a=sc.nextInt();
10 b=sc.nextInt();
11 }
12 void display()
13 {
14 s= a+b;
15 System.out.println("The result is :" +s);
16 }
17 void main()
18 {
19 sum ob= new sum();
20 ob.input();
21 ob.display();
22 }
23 }
266266 Touchpad Computer Applications-X

