• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how is "castOther " object which is of type object gets casted to object bof Account type

 
monis raza
Ranch Hand
Posts: 38
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A cast (for a reference) doesn't convert the object. It will only work if the object in question is actually an Account object, and all it does is change the type of the reference.

What the cast does is tell the compiler "See that Object reference you've got? Well, it's actually pointing at an Account object. So please treat it as one".
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a few occasions where the compiler won’t believe youOtherwise the compiler is much more trusting than we are: it thinks you are telling it the truth, and that you know what you are doing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic