File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Widening & Boxing" Watch "Widening & Boxing" New topic

Widening & Boxing

swapna mallipudi

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

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

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

Thank you Neha Daga & Vinit Sharma
I agree. Here's the link:
subject: Widening & Boxing
It's not a secret anymore!