1
2 ##How to write Mathods:-
3 AccessModifiers ReturnType mathodName(Arguments/Parameters)
4 {
5 body of the Mathod;
6 }
7 Example: public void addition(int a, int b)
8 {
9 int sum = a+b;
10 }
11 ##TYPES OF MATHODS:-
12 1) Without Arguments Without Return type
13 2) With Arguments Without Return type
14 3) Without Arguments With Return type
15 4) With Arguments With Return type
16
17
18 //Mathod: 1: Without Arguments Without Return type
19
20 //Example: 1: WAP to do sum of two numbers by using addition mathod;
21 public class Mathod
22 {
23 public static void main(String[] arg)
24 {
25 Mathod m1 = new Mathod();
26 [Link](); //mathod call without arguments
27 }
28 void addition() //mathod Without Return type Without Arguments
29 {
30 int a=5;
31 int b=7;
32 int sum = a+b;
33 [Link]("Addition of two numbers = "+sum);
34 }
35 }
36 //Mathod: 2: With Arguments Without Return type
37
38 //Example: 2: WAP to do sum of two numbers by using addition mathod;
39 public class Mathod
40 {
41 public static void main(String[] arg)
42 {
43 int a=5;
44 int b=7;
45 Mathod m2 = new Mathod();
46 [Link](a,b); //mathod call with arguments
47 }
48 void addition(int x,int y) //mathod Without Return type With Arguments
49 {
50 int sum = x+y;
51 [Link]("Addition of two numbers = "+sum);
52 }
53 }
54 //Mathod: 3: Without Arguments With Return type
55
56 //Example: 3: WAP to do sum of two numbers by using addition mathod;
57 public class Mathod
58 {
59 public static void main(String[] arg)
60 {
61 Mathod m3 = new Mathod();
62 int add = [Link](); //mathod call without arguments
63 [Link]("Addition of two numbers = "+add);
64 }
65 int addition() //mathod With Return type Without Arguments
66 {
67 int a=5;
68 int b=7;
69 int sum = a+b;
70 return sum;
71 }
72 }*/
73 //Mathod: 4: With Arguments With Return type
74
75 //Example: 4: WAP to do sum of two numbers by using addition mathod;
76 public class Mathod
77 {
78 public static void main(String[] arg)
79 {
80 int a=5;
81 int b=7;
82 Mathod m4 = new Mathod();
83 int add = [Link](a,b); //mathod call with arguments
84 [Link]("Addition of two numbers = "+add);
85 }
86 int addition(int x,int y) // mathod With Return type With Arguments
87 {
88 int sum = x+y;
89 return sum;
90 }
91 }