Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Widening and boxing 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 "Widening and boxing" Watch "Widening and boxing" New topic
Author

Widening and boxing

J Brewer
Ranch Hand

Joined: Jul 10, 2006
Posts: 46
I ran the following code,




and I got the same answer as the book, 4 3. However, I don't understand why
the answer is not 3 3. Since s is of type Short, couldn't you box short to Short, then widen Short to Integer? The only answer I can think of is maybe because Short is now an object not a primitive, it is a subclass of Number, not Integer? Is that correct?
Stephen O'Kane
Greenhorn

Joined: Aug 17, 2005
Posts: 26
you can widen from short to int, but not from Short to Integer, so your reckoning is correct
J Brewer
Ranch Hand

Joined: Jul 10, 2006
Posts: 46
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Widening and boxing
 
Similar Threads
Boxing & Widening
varargs doubt
Question on widening ,boxing
K&B Mock Question 5
Widening beats boxing?