sum1 is an Integer type object, and that's why it's allowing method calls. But sum2 is not any reference of any class, it's primitive type data. As you can't call any method on primitive type, this is the reason java introduces the concepts of these wrapper classes, for e.g. Integer,Double.
Joined: May 16, 2008
Swastik , thanks a lot for the clarification .
Joined: Nov 01, 2011
As a friendly reminder, there will be a compilation error if we do this
This is in one of the practice exam.
But this will work:
The new Integer(1) will be unboxed and assigned to a.