All IT Courses 50% Off
JAVA Tutorials

Method overriding in Java

Introduction to Method Overriding:

  • Firstly, let’s understand the overriding in object-oriented terms. Overriding means override the functionality of an existing method.
  • If the subclass or child class has the same method as we declared in the superclass or parent class, it is called Method overriding in Java.

Use of Method Overriding:

  • It is used to give us the implementation of a method that is already provided by its superclass.
  • It is used for runtime polymorphism (many forms).

Rules about the Method Overriding:

  • First, the method signature, like method name, its parameter list, and also the return type, have to match exactly.
  • The method should have the same name as same as the parent class.
  • The method must have the same parameter as the same as the parent class has.

Method overriding

Method overriding in Java

Difference between Method Overloading and Method Overriding:

Method Overloading:

    • It is in the same class, where we have more than one method having the same name but different parameters.   

Method Overriding:

  • It is one of the methods which is also defined in the subclass as the same in the superclass
  • In this, the parameters of the method remain the same.    

Note: Method Overriding is mostly used to achieve Run Time Polymorphism.

Facebook Comments
Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close

Get Java Training Online
Course Now at 50%OFF!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys will use this information to be in touch with you for providing updates.

Get Python Course
worth 499$ for FREE!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys Blog will use the information you provide on this form to be in touch with you and to provide updates and marketing.