-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypesOfMethod.java
More file actions
44 lines (36 loc) · 880 Bytes
/
TypesOfMethod.java
File metadata and controls
44 lines (36 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package methodsExample;
public class TypesOfMethod {
// 1.method with no return type with no arguments.
void print() {
System.out.println("Hello Java");
}
// 2.method with no return type with arguments.
void print_1(int a, int b) {
int c;
c = a + b;
System.out.println("Addition is : " + c);
}
// 3.method with return type with arguments.
int print_2(int a, int b) {
int c;
c = a - b;
System.out.println("Substraction is : " + c);
return c;
}
// 4.method with return type with no arguments.
int print_3() {
int a = 10;
int b = 4;
int c;
c = a * b;
System.out.println("Multiplication is : " + c);
return c;
}
public static void main(String[] args) {
TypesOfMethod obj = new TypesOfMethod();
obj.print(); // Hello Java
obj.print_1(2, 6); // Addition
obj.print_2(5, 2); // Substraction
obj.print_3(); // Multiplication
}
}