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

7th Jan 2020, 9:58 AM
Nagaraj P
Nagaraj P - avatar
1 Answer
+ 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"); }
7th Jan 2020, 2:14 PM
Tibor Santa
Tibor Santa - avatar