This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance" Watch "inheritance" New topic


SenthilNathan CAlagan

Joined: Jun 21, 2001
Posts: 4
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?
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
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.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Have you checked out Aspose?
subject: inheritance
It's not a secret anymore!