You're mistaken.
Animal animal = zoo.getAnimal();
Can I do animal.bark() or animal.fly() ? All I know is that it's an Animal of some sort, may or may not be an instance of the Dog or Bird subclasses of Animal.
Animal animal = zoo.getAnimal();
Can I do animal.bark() or animal.fly() ? All I know is that it's an Animal of some sort, may or may not be an instance of the Dog or Bird subclasses of Animal.
If the superclass-subclass relationships aren't in place for you (worse yet, they're not set up how you want them to be set up), this hack accomplishes a similar effect with no refactoring.
Unless the Animal type responds to fly and bark (unlikely in this scenario) that looks like a compile error to me.