I need some help in understanding the concept. Please refer following example and how code shows different outputs?
Scenario-1: If I used public Confusing(Object o){
this method signature then output is object, but if I used public Confusing(StringBuffer sb){
String Buffer output is printing?
public class Confusing {
public Confusing(Object o){
System.out.println("Object");
}
public Confusing(StringBuffer sb){
System.out.println("String Buffer");
}
public static void main(String[] args) {
new Confusing(null);
}
}
Scenario-2: If I used use public Confusing(Object o){
this method signature then output is object, but if I used public Confusing(double[] dArray){
then why output is Double Array?
public class Confusing {
public Confusing(Object o){
System.out.println("Object");
}
public Confusing(double[] dArray){
System.out.println("Double Array");
}
public static void main(String[] args) {
new Confusing(null);
}
}
Scenario-3 If I used following code then why I'm getting following error? How we can fixed this error?
The constructor Confusing(Object) is ambiguous
public class Confusing {
public Confusing(Object o){
System.out.println("Object");
}
/*public Confusing(double[] dArray){
System.out.println("Double Array");
}*/
public Confusing(String s){
System.out.println("String");
}
public Confusing(StringBuffer sb){
System.out.println("String Buffer");
}
public static void main(String[] args) {
new Confusing(null);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The constructor Confusing(Object) is ambiguous
Kindly help me to understand the concept.