-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathambigious.java
More file actions
47 lines (39 loc) · 1.26 KB
/
ambigious.java
File metadata and controls
47 lines (39 loc) · 1.26 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
/*
program shows the ambiguous overloading of method
AIM :: To know about Ambiguous Overloading Concept in Java
*/
package basic_package;
public class ambiguous_overloading {
public static void main(String[] args) {
// System.out.println(max(1, 2));
// here both max method is possible , because of neither is better than other the invocation is ambiguous , returning in compile error
}
/**
* The max method will return the maximum among two value passes in the argument.
*
* @param n1 to store first number (integer)
* @param n2 to store second number (double)
* @return The maximum of 2 numbers
*/
public static double max(int n1, double n2) {
if (n1 < n2)
return n1;
return n2;
}
/**
* The max method will return the maximum among two value passes in the argument.
*
* @param n1 to store first number (double)
* @param n2 to store second number (integer)
* @return The maximum of 2 numbers
*/
public static double max(double n1, int n2) {
if (n1 < n2)
return n1;
return n2;
}
}
/*
Here Compiler unable to find the best method among 2 overloaded methods :(
So this situation is known as Ambiguous Overloading.
*/