-
Notifications
You must be signed in to change notification settings - Fork 0
/
overloading_main.java
48 lines (40 loc) · 1.72 KB
/
overloading_main.java
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
class overloading_main{
static double sum(double a, double b)
{
System.out.println("Inside overloaded function sum taking two inputs as double");
return (a+b);
}
static int sum(int a, int b)
{
System.out.println("Inside overloaded function sum taking two inputs as int");
return (a+b);
}
static double sum(double a)
{
System.out.println("Inside overloaded function sum taking one input as double and increasing by 10");
return (a+10);
}
public static void main(String args[])
{
//calling by giving two double arguments.
System.out.println("calling by giving two double arguments.");
System.out.println(sum(10.345,12.458)); //call function sum(double,double)
System.out.println();
//calling by giving one double argument and one int argument.
System.out.println("calling by giving one double argument and one int argument.");
System.out.println(sum(10.345,12)); //call function sum(double,int)
System.out.println();
//calling by giving two integer arguments.
System.out.println("calling by giving two integer arguments.");
System.out.println(sum(100,56)); //call function sum(int,int)
System.out.println();
//calling by giving one integer argument.
System.out.println("calling by giving one double argument.");
System.out.println(sum(56.345)); //call function sum(double)
System.out.println();
//calling by giving one integer argument.
System.out.println("calling by giving one integer argument.");
System.out.println(sum(25)); //call function sum(int)
System.out.println();
}
}