Thursday , August 16 2018
Home / Java / Method Overriding In Java

Method Overriding In Java

If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in java.

In other words, If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding.

The benefit of overriding is: ability to define a behaviour that’s specific to the subclass type which means a subclass can implement a parent class method based on its requirement.

Rules for Java Method Overriding

  • method must have same name as in the parent class
  • method must have same parameter as in the parent class.
  • must be IS-A relationship (inheritance).

Example of method overriding

Using the super keyword:

When invoking a superclass version of an overridden method the super keyword is used.

 

About admin

Check Also

Internal Working of HashMap in Java

In this article, we will see how hashmap’s get and put method works internally. What ...

Leave a Reply