Please examine the following code : -
public class Animal111 extends Horse{
public static void main(
String[] args) {
Animal111 a = new Animal111();
Horse b= new Animal111();
a.eat();
b.eat();
}
public void eat(){
System.out.println("Inside Animal");
}
}
class Horse{
public void eat(){
System.out.println("I am not being used anytime anywhere");
System.out.println("Inside Horse");
}
}
The output of the foll program is : -
Inside Animal
Inside Animal
My question is that if " eat() " inside Horse class is never used, why I am getting compile time error while commenting out the " eat () " of Horse class i.e
public class Animal111 extends Horse{
public static void main(String[] args) {
Animal111 a = new Animal111();
Horse b= new Animal111();
a.eat();
b.eat();
}
public void eat(){
System.out.println("Inside Animal");
}
}
class Horse{
//public void eat(){
//System.out.println("I am not being used anytime anywhere");
//System.out.println("Inside Horse");
//}
}
The above code gives compile time error at " b.eat(); "