Sunday, June 22, 2014

Method Overriding

Java method overriding | java override static method | method overriding in java example

“Method Overriding is the concept of Object Oriented Programming in which same name methods are used in different classes (Superclass and Subclass).” Or we can say that, when a subclass inherits methods (with the same name) from a superclass, sometimes it will modify the implementation of a method defined in the superclass called Method Overriding.
Following rules are necessary to achieve Overriding: -
  •   Method must have same name as in super/parent class.
  •   Method must have same parameter as in the super/ parent class.

Example of Overriding in Java: -

Fig: - Example in java
Description: - In the main() method of SubExample class we invoked the display() method, which hides the display() method of class Sup Example and gives the output from display method of SubExample class. This is done by Method Overriding.

No comments:

Post a Comment