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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Wrappers and Autoboxing" Watch "Wrappers and Autoboxing" New topic
Author

Wrappers and Autoboxing

Pinki Roy
Greenhorn

Joined: May 16, 2008
Posts: 20


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

Swastik Dey
Ranch Hand

Joined: Jan 08, 2009
Posts: 1196

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: 20
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Wrappers and Autoboxing
 
Similar Threads
Getting an Average
Adding numbers...
Turn Based Strategy Games
toString
Newbie, Please Help: Why can I not get the numbers to display