N Pats wrote:Animal a = new Cat();
1) Only eat() can be called on object a since it exists in Animal and Cat. meow() cannot be called.
Here is the Head First analogy:
Think of the variable, Animal a, as the 'remote control' to your object and think of each method of the class as a button on the remote control.
The reason you can't call the meow() method from the Animal control is because the button doesn't exist.
But the VERSION of the methods called are the one within Cat.
I noticed that the method eat() that is called is the one inside Cat class.
This is because although the reference variable is of type Animal, the JVM actually knows which type of object the variable is pointing to. Because of this knowledge the JVM automatically calls the overridden method of the actual object.
However, if you declare the method of the Animal class static, it will call the eat() from the Animal class, not cat.