Method overriding in java:
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java.
When a class is inheriting a method from a superclass of its own, then there is an option of overriding the method provided it is not declared as final. The advantage of using overriding is the ability to classify a behaviour that's specific to the child class, and the child class can implement a parent class method based on its necessity.
Rules for methods overriding
1)The argument list should be exactly the same as that of the overridden method.
2)The return type should be the same or a subtype of the return type declared in the original overridden method in the superclass.
3)The access level cannot be more restrictive than the overridden method's access level. For example: If the superclass method is declared public then the overriding method in the subclass cannot be either private or protected.
4)Instance methods can be overridden only if they are inherited by the subclass.
5)A method declared final cannot be overridden.
6)if a method cannot be inherited, then it cannot be overridden.
Eg: