class sample {
void meth(sample s){
System.out.println("In Sample");
}
void meth(Object o){
System.out.println("In object");
}
void meth(
String s){
System.out.println("In String");
}
}
public class test{
public static void main(String args[]){
new sample().meth(null);
}
}
Hi Friends,
The above program fails to compile and the compiler throws the following message.
"test.java:17: reference to meth is ambiguous, both method meth(sample) in sample
and method meth(java.lang.String) in sample match
new sample().meth(null);
^
1 error"
But if I declare a reference variable sample s=null or String s=null, the program complies.Can any one explain how this works?
regards,
Raja