Hi there,
the following are two ways of coding overloaded methods in super and subclass.
Case 1:
public class A extends Base {
public static void main(
String[] args) {
A obj=new A();
char c = 'V';
int i=100;
System.out.println(obj.m1(c));
System.out.println(obj.m1(i));
}
public char m1(long x) {
return 'X';
}
}
class Base {
public char m1(int x) {
return 'Y' ;
}
}
_______________________________________________________________
This gives compile time error of m1 having ambiguous reference to
m1(int) and m1(long)
________________________________________________________________
case 2:
public class A extends Base {
public static void main(String[] args) {
A obj=new A();
char c = 'V';
int u=100;
System.out.println(aww.m1(c));
System.out.println(aww.m1(u));
}
public char m1(long x) {
return 'X';
}
public char m1(int x) {
return 'Z' ;
}
}
class Base {
public char m1(int x) {
return 'Y' ;
}
}
_______________________________________________________________
This compiles ok.
_______________________________________________________________
Could anyone of u tell me the reason of this difference in behaviour.
Thanks
Raj