aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrappers and Autoboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrappers and Autoboxing" Watch "Wrappers and Autoboxing" New topic
Author

Wrappers and Autoboxing

Pinki Roy
Greenhorn

Joined: May 16, 2008
Posts: 22


Why does line 4 give me compile time error where as line 3 does not give me any error.

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

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.


Swastik
Pinki Roy
Greenhorn

Joined: May 16, 2008
Posts: 22
Swastik , thanks a lot for the clarification .
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrappers and Autoboxing