1
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.

kittu
  • 6,662
  • 21
  • 91
  • 185
  • This has nothing to do with widening. That has to do with _wiring_ and _inheritance_. Widening an `int` to a `long` works because a `long` can represent every possible value of `int`. Inheritance works because a an `Integer` _is a_ `Number` - no conversion happens. – Boris the Spider May 01 '15 at 16:26
  • "5.1.5. Widening Reference Conversion" from the docs is confusing. Isn't it talking about widening? – kittu May 01 '15 at 16:28

0 Answers0