This is because we cannot have two methods in classes with the same name, but with different types of returned data.
A subclass cannot declare a method with the same name as an existing method in a superclass with a different return type.
However, a subclass can declare a method with the same signature as the superclass. We call it "Overriding."
You need to have this,
class A {
public void eat() { }
}
class B extends A {
public void eat() { }
}
OR
class A {
public boolean eat() {
}
}
class B extends A {
public boolean eat() {
}
}
It is good practice to mark overwritten methods with annotations @Override:
class A {
public void eat() { }
}
class B extends A {
@Override
public void eat() { }
}