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

inheritance

 
SenthilNathan CAlagan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sub class reference can be assigned to super class reference.
But super class reference cannot be assigned to sub class reference(without explicit casting).Why it is so?
Can anyone explain me in detail?
Thanks,
Senthil
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Subclass object ALWAYS is a Superclass object by definition. However, the reverse is not true.
For example, Dog "is a" Animal, but Animal is NOT always a Dog.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic