In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.
When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass. The version in the superclass will be hidden. If you wish to access the superclass’ version of an overridden method, you can do so by using ‘super’.
In order for any particular method to override another correctly :
- The return type, method name, type and order of arguments must be identical to those of a method in a parent class.
- The accessibility must not be more restrictive than original method.
The method must not throw checked exceptions of classes that are not possible for the original method.