File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ //Overloading
2
+ //changing number of arguments
3
+
4
+ class Over
5
+ {
6
+ static int add (int a ,int b )
7
+ {
8
+ return a +b ;
9
+ }
10
+ static int add (int a ,int b ,int c )
11
+ {
12
+ return a +b +c ;
13
+ }
14
+ }
15
+ class TestOverloading
16
+ {
17
+ public static void main (String [] args )
18
+ {
19
+ System .out .println (Over .add (10 ,10 ));
20
+ System .out .println (Over .add (20 ,10 ,30 ));
21
+ }
22
+ }
23
+
24
+ //changing data type of arguments
25
+
26
+ // class Over
27
+ // {
28
+ // static int add(int a,int b)
29
+ // {
30
+ // return a+b;
31
+ // }
32
+ // static int add(int a,int b,int c)
33
+ // {
34
+ // return a+b+c;
35
+ // }
36
+ // }
37
+ // class TestOverloading
38
+ // {
39
+ // public static void main(String[] args)
40
+ // {
41
+ // System.out.println(Over.add(10,10));
42
+ // System.out.println(Over.add(20,10,30));
43
+ // }
44
+ // }
45
+
46
+
47
+ class Adder
48
+ {
49
+ static int sum (int a , int b )
50
+ {
51
+ return a +b ;
52
+ }
53
+ static double sum (double a , double b )
54
+ {
55
+ return a +b ;
56
+ }
57
+ }
58
+ class TestOverloading1
59
+ {
60
+ public static void main (String [] args )
61
+ {
62
+ System .out .println (Adder .sum (10 ,40 ));
63
+ System .out .println (Adder .sum (16.7 ,18.4 ));
64
+ }
65
+ }
66
+
You can’t perform that action at this time.
0 commit comments