Posts

Showing posts from December, 2022

Day32: Method Overriding

 Method Overriding Whenever a child class has method with SAME PROTOTYPE as parent class METHOD, then we say that the child class has overridden the parent class method. class A { public void show() { ............. ............. ............. } } class B extends A { public void show() { ................. } } Prototype: Access modifier, return type, Argument list, Name Both the classes access modifier is same. Both the classes have return type is Void. Both the classes show name is show(). Both the classes show is non parameterized. It means Class B 'show()' overide the Class A 'show()'. Why do we perform method overriding? Sometimes it happens that the functionality (logic ) of  a method defined in Parent class may not be suitable for the child class. For Example : The logic of sound() method in the class CAT is not suitable for the class TIGER because Tiger makes a different sound. In this case the programmer of TIGER class must compulsory overr