Skip to Content

 

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

  MainClass_Defn.PNG

  • Define sub class.Here method mainclass_method is redefined.Addition of FINAL will restrict furter redefinition of method in subclasses.

SubClass_Defn.PNG

  • Implementation of main class.

MainClass_Main.PNG

  • Implementation of sub class.

SubClass_Impl.PNG

  • Create the object and Call methods

Program_main.PNG

 

Output of the above example will be as below.

Output.PNG

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply