This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Widening & Boxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Widening & Boxing" Watch "Widening & Boxing" New topic
Author

Widening & Boxing

swapna mallipudi
Greenhorn

Joined: Sep 10, 2009
Posts: 11
This question is from scjptest.com



The answer is C. I was thinking as B. Int can be boxed to Integer than Widened to Long. Since Boxing & Widening are allowed I picked B. But, why is it C?

Thank you.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Integer is not subclass of Long so it can't be widened. All wrapper classes are same level classes so, one wrapper class can't be widened to another.


SCJP 1.6 96%
appu sharma
Ranch Hand

Joined: Sep 20, 2009
Posts: 104

you should refer K&B6 page 252 you will get the answer
you directly doesnt cast int ------>Integer--------->Long This is worng.
but you can do int--------->object--------->then cast it into Long This can be possible.


It doesn't matter if you win by an inch or a mile; winning's winning.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Golden Rules widening boxing varargs


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
swapna mallipudi
Greenhorn

Joined: Sep 10, 2009
Posts: 11
Got it.

Thank you Neha Daga & Vinit Sharma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Widening & Boxing
 
Similar Threads
widening & boxing with var-args
SCJP problem with boxing
Autocast
Widening and Autooboxing
Autoboxing