Let\'s take this simple Java code:
public class Animal {
public void eat() {
System.out.println(\"Generic Animal Eating Generically\");
}
}
public
This is happens because of method overriding. In method overriding, the reference type does not matter, it is the object type that matters. Animal ah is simply a reference to the object and the actual object is of type Horse. So, Horse's method will be called instead of reference type Animal's method.