Below code is running fine and printing 'Constructor B.'
as an output.
public class Test
{
public Test(Object obj)
{
System.out.println("Constructor A.");
}
public Test(String s)
{
System.out.println("Constructor B.");
}
public static void main(String args[])
{
new Test(null);
}
}
But the below code is giving me compilation error 'The constructor Test(Integer) is ambiguous'
public class Test
{
public Test(Integer obj)
{
System.out.println("Constructor A.");
}
public Test(String s)
{
System.out.println("Constructor B.");
}
public static void main(String args[])
{
new Test(null);
}
}
Can someone please explain me the reason?