Hi everybody, i have one doubt regarding following question.
class Animal {
void eat(Object o){
System.out.println("In Animal Object");
}
}
class Horse extends Animal{
void eat(Object o){
System.out.println("In Horse Object");
}
void eat(
String str){
System.out.println("In Horse String");
}
}
public class
Test {
public static void main(String[] args){
Animal a=new Horse(); // Line 1
a.eat("grass"); // Line 2
}
}
Output is "In Horse Object"...
As we are calling the method with string parameter, so void eat(String str) of Horse should be called.
Please explain that actual concept behind this.