forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethod_overloading.java
80 lines (63 loc) · 1.31 KB
/
Method_overloading.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Java Program for Method overloading
// By using Different Types of Arguments
// Class 1
// Helper class
class Helper {
// Method with 2 integer parameters
static int Multiply(int a, int b)
{
// Returns product of integer numbers
return a * b;
}
// Method 2
// With same name but with 2 double parameters
static double Multiply(double a, double b)
{
// Returns product of double numbers
return a * b;
}
}
// Class 2
// Main class
class basic {
// Main driver method
public static void main(String[] args)
{
// Calling method by passing
// input as in arguments
System.out.println(Helper.Multiply(2, 4));
System.out.println(Helper.Multiply(5.5, 6.3));
}
}
// Java program for Method Overloading
// by Using Different Numbers of Arguments
// Class 1
// Helper class
class abc {
// Method 1
// Multiplication of 2 numbers
static int Multiply(int a, int b)
{
// Return product
return a * b;
}
// Method 2
// // Multiplication of 3 numbers
static int Multiply(int a, int b, int c)
{
// Return product
return a * b * c;
}
}
// Class 2
// Main class
class simple {
// Main driver method
public static void main(String[] args)
{
// Calling method by passing
// input as in arguments
System.out.println(abc.Multiply(2, 4));
System.out.println(abc.Multiply(2, 7, 3));
}
}