I would like to know: Why overriding method cannot have a more restrictive access modifier than method being overriden?
For example:
class Animal{
public void eat(){
System.out.println("Generic Animal Eating Generically");
}
}
class Horse extends Animal{
public void eat(){
System.out.println("Horse eating hay, oats, and horse treats");
}
}
In Horse class, why can't I write the code like this:
private void eat(){
System.out.println("Horse eating hay, oats, and horse treats");
}
or
protected void eat(){
System.out.println("Horse eating hay, oats, and horse treats");
}