This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Widening & Boxing

 
swapna mallipudi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
appu sharma
Ranch Hand
Posts: 104
Java Netbeans IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Golden Rules widening boxing varargs
 
swapna mallipudi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.

Thank you Neha Daga & Vinit Sharma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic