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.
To come back to IS A(N), you will need to cast if you can't use IS A(N) but can use MIGHT BE A(N):
Animal IS A Lion? No. But Animcal MIGHT BE A Lion? Sure.
If this is also not the case you can never cast between the two: String IS AN Integer? No. String MIGH BE AN Integer? No.
Please note that you should never cast unless you are really sure that the cast will succeed, for instance by checking with instanceof. Remember, if the cast is invalid it will throw a ClassCastException. This happens if the Animal MIGHT BE A Lion but is in fact a Tiger, and you still try to cast it to a Lion. [ July 17, 2008: Message edited by: Rob Prime ]
Suppose any Superclass has 3 Characteristics like (1, 2, 3). So its obvious that Subclass should have all the three Characters of its Superclass in it. And it can also has its own characteristics (4,5)(it means subclass is more specific).
Now, Subclass has total 5 characteristics (i.e. 1, 2, 3, 4, 5 ).
Now want to cast Superclass in to Subclass means you want Superclass of (3charactoristics) exactly like Subclass of (5 characteristics ).
How can characteristics 4 & 5 will come in Superclass?