An Animal has no playDead() method. Your reference variable animal is of type Animal so you cannot do animal.playDead().
Now, if at runtime, you know animal is going to be a Dog (using instanceof), you can call playDead() on this object, but only if you promise the compiler that this Animal is really a Dog. So what you have to do is cast animal to a Dog like this: (Dog)animal. Then you can call playdead() like this: ((Dog)animal).playDead().
By using instanceof before the casting of the animal to a Dog you have avoided a possible ClassCastException. So instead of having a nasty RuntimeException appearing suddenly out of nowhere, you just don't call playDead() when it is inapproriate to do so - like on a ChargingHeffalump or a ManEatingTigger (or worse, a Snark which turns out to be a BooJum). [ July 27, 2006: Message edited by: Barry Gaunt ]
Joined: May 19, 2006
Thank You, its very clear now.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com