-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathTestMethod1.java
More file actions
58 lines (47 loc) · 1.45 KB
/
TestMethod1.java
File metadata and controls
58 lines (47 loc) · 1.45 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package MethodOverloading;
public class TestMethod1 {
//Yes we can overload static method
static void add(int a){
System.out.println("Static Method with (int)");
}
static void add(int a, String s){
System.out.println("Static Method with (int, String)");
}
//Yes we can overload method with different No. of arguments.
void add(int a, int b){
System.out.println("Method with (int, int)");
}
void add(int a, int b, int c){
System.out.println("Method with (int, int, int)");
}
//Yes we can overload method with different type of argument
// but the no. of argument is same.
void add(int a, double b){
System.out.println("Method with (int,double)");
}
//Yes we can overload method with same type and no. of arguments.
//but the argument position is different.
void add(double a, int b){
System.out.println("Method with (double, int)");
}
// static void add(int a, int b){
// System.out.println("Method with (int, int)"); (Not possible: Compile Time Error)
// }
void add(int ... a){ //var args (int … a) are nothing but the arrays (int[] a).
System.out.println("Var args method (int... a)");
}
// void method(int[] a)
// {
// System.out.println(2); //Duplicate CTE;
// }
public static void main(String... agrs){
add(10);
add(10,"abc");
TestMethod1 t1=new TestMethod1();
t1.add(12.0, 3);
t1.add(4, 5.0);
t1.add(3 , 7);
t1.add(4, 5, 6);
t1.add(12,2,0,12);
}
}