Skip to content

Commit f9a0684

Browse files
authored
Merge pull request #884 from KeerthanaPravallika/KeerthanaS
Added Method overloading in java
2 parents 1185e9f + 1041025 commit f9a0684

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Method overloading : If a class has multiple methods having same name but different in parameters or change in data type , it is known as Method Overloading.
3+
*/
4+
5+
class method_overloading
6+
{
7+
int res;
8+
void addition(int n1,int n2)
9+
{
10+
res = n1+n2;
11+
System.out.println("Addition with two parameters");
12+
System.out.println("Sum of "+n1+" and "+n2+" is "+res);
13+
}
14+
void addition(int n1,int n2,int n3)
15+
{
16+
res = n1+n2+n3;
17+
System.out.println("Addition with three parameters");
18+
System.out.println("Sum of "+n1+" , "+n2+" and "+n3+" is "+res);
19+
}
20+
}
21+
public class meth_ovel
22+
{
23+
public static void main(String[] args)
24+
{
25+
method_overloading obj = new method_overloading();
26+
obj.addition(10,20);
27+
obj.addition(40,50,60);
28+
}
29+
}

0 commit comments

Comments
 (0)