0
How overridding takes place in the following code
class Human{ public void eat() { System.out.println("Human is eating"); } } class Boy extends Human{ public void eat(){ System.out.println("Boy is eating"); } public static void main( String args[]) { Human obj = new Boy(); obj.eat(); } } https://code.sololearn.com/crNf7K435nKG/?ref=app
2 Antworten
+ 3
When we override a parent class' method, it is good practice to annotate it. Not mandatory, but if the parent class changes (e.g. the method signature) then it is easier to debug the error.
class Boy extends Human{
@Override
public void eat(){
System.out.println("Boy is eating");
}