-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading3.java
More file actions
30 lines (25 loc) · 824 Bytes
/
Overloading3.java
File metadata and controls
30 lines (25 loc) · 824 Bytes
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
public class Overloading3
{
public void mth(String s)
{
System.out.println("String version");
}
public void mth(StringBuffer sb)
{
System.out.println("StringBuffer version");
}
public void mth(Object o)
{
System.out.println("Object version");
}
public static void main(String []args)
{
Overloading3 o=new Overloading3();
o.mth(new Object()); //Object Version
o.mth("prabhu"); //String Version
o.mth(new StringBuffer ("prabhu")); //StringBuffer Version
//o.mth(null); -> CE: reference to mth is ambiguous ->both method mth(String) in Overloading3 and method mth(StringBuffer) in Overloading3 match
}
}
/*while resolving overloaded methods compiler will give the precedence
for child type argument when compared with parent type argument.*/