Hi,
RE: The "Java 2" book by Kathy Sierra & Bert Bates, Chapter 5, page 311.
Given...
public class Horse extends Animal {
eat(){}
eat(
String){}
}
public classAnimal {
eat(){}
}
Table 5-3 explains that if a method is overloaded then the "Reference Type" of the object determines which overloaded version is run. Whereas if the method is overridden then the "Object Type" determines which method is selected.
Logically, if an object invokes eat(), since the method is overridden, then the object type at run time determines whether to invoke the Animal.eat() or the Horse.eat(). Contrariwise, if an object invokes eat(String), since the method is overloaded the reference type at compile time determines the method signature.
BUT...suppose...Animal also has eat(String){}
public class Horse extends Animal {
eat(){}
eat(String){}
}
public classAnimal {
eat(){}
eat(String) {} //This has been added...
}
Now, is eat(string) overridden or overloaded or both? How do I calculate whether Horse.eat(String) or Animal.eat(String) is run?
Cheers,
Simon.