• 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