• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One Confusion

 
Ahmad Mudassir
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every one !
Some words about casting that you can cast any primitive to any other primitive type except boolean.(from higher to lower capacity otherwise from lower to higher implicit cast is done)
And with objects you can assign reference of an object to any other object with casting(subclass object reference to superclass object reference or to an interface which is implemented by that class is done through implicit cast).
But what in the case of Wrapper classes they can not be cast to each other why?
is because they are final. so final class object's references can not be casted.
Any one can solve this problem
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ahmad,
you've answered your own quesion in away.
Wrapper classes do not participate in parent child relationship.
mean Integer is not extended from Short and vice versa and so on.
although most of them are derived from class Number.and henceforth are sibling classes.
but casting among siblings in not allowed in java.

regards
deekasha
 
Ahmad Mudassir
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx deekasha for your clarity
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic