public class Lanka {
public Lanka(Object o)
{
System.out.println("Obj");
}
public Lanka(Number o)
{
System.out.println("Num");
}
public Lanka(Integer o)
{
System.out.println("Int");
}
public static void main(String[] args) {
new Lanka(null); //prints Int
}
}
I have heard of primitive type widening but how the reference type widening works.
From the java docs, it says
From any reference type S to any reference type T, provided that S is a proper supertype of T.
However, I couldn't find an example anywhere on web to understand it properly.