Using REDEFINITION addition, method implemented in superclass can be reimplemented in subclasses.
When method is called with subclass object reference then method which is redefined in subclass will be called.
Static methods and constructor can not be redefined.
Interface of the method can not be changed in the redefinition of the method.
- Define main class
- Define sub class.Here method mainclass_method is redefined.Addition of FINAL will restrict furter redefinition of method in subclasses.
- Implementation of main class.
- Implementation of sub class.
- Create the object and Call methods
Output of the above example will be as below.