Method Overriding   

★ The method, method body (the code inside the method) from one (super class) to another (sub class), change is method overring.



Super Class  →   Monkey → Eat ();

                                               Climb ();

Class Man Extends Monkey 

Sub Class      →   Man       → Eat ();

                                                Climb ();

Monkey super class ,

                                  Eat () - Code 

                                  Climb () - Code 

Man Sub Class ,

                                  Eat () - Code 

                                  Climb - Code

Method body - ( { // method body } ) = Diffrent

Ex : 

        Class Monkey {

        void climb () {

        // use body 

        }

        }

        Class Man Extend Monkey {   

        void climb () { 

        // use ladder 

        }

        }

Ex :  A  →  Abc  →  (Super Class)

                              ↕

         B  →  Efg  →  (Sub Class)

         Abc a   =   new   Efg   ();

                           ↑         ↑

       (Parent)   (Same)   (Child)


                                                                                                                                                 D.M.T. Dasanayaka
                                                                                                                                                 Software Engineer
                                                                                                                                                 Java Development.


 



 

Comments