Free Source Code and Tutorials

Custom Search

Method Overriding in Java

Method Overriding

If subclass/child class has the same method as declared in the super/parent class (signature of method in both class should be same), 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.

Rules of Method Overriding:

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

Let us take one example:

  1. class Car{
  2. void run(){System.out.println("Car is running");}
  3. }
  4. class Mercedes extends Car{
  5. void run(){System.out.println("Mercedes is running safely");}
  7. public static void main(String args[]){
  8. Mercedes obj = new Mercedes ();
  10. }
  11. }
Facebook Comments
(Visited 1 times, 1 visits today)
Share this

Check Your Domain Ranking

1 Comment

Add a Comment
  1. Greetings! Ѵery useful advice ԝithin tɦis article!
    It’s the lіttle cҺanges thаt wіll make tthe moset significant cɦanges.
    Thankms a lot fⲟr sharing!

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: