Method Overloading Vs Method Overriding

Method Overloading:

  • Method Overloading is a Compile time polymorphism. 
  • In method overloading, more than one method shares the same method name with different signature in the class. 
  • In method overloading, return type can or can not be be same, but we must have to change the parameter because in java, we can not achieve the method overloading by changing only the return type of the method.


  • Full Example:

class MethodOverloadingEx{ 
   static int add(int a, int b){return a+b;} 
   static int add(int a, int b, int c){return a+b+c;} 

    public static void main(String args[]) {
      System.out.println(add(4, 6));
      System.out.println(add(4, 6, 7));
    }
}
Method Overriding:

  • Method Overriding is a Run time polymorphism. 
  • In method overriding, the derived class provides the specific implementation of the method that is already provided by the base class or parent class. 
  • In method overriding, the return type must be the same.


  • Full Example:

class Animal{ 
      void eat(){System.out.println("eating.");} 
      } 
    class Dog extends Animal{ 
    void eat(){System.out.println("Dog is eating.");} 
     } 
   class MethodOverridingEx{ 
    public static void main(String args[]) {
      Dog d1=new Dog();
      Animal a1=new Animal();
      d1.eat();
      a1.eat();
    }
}

Difference:

  • Method overloading is a compile-time polymorphism.
  • Method overriding is a run time polymorphism.


  • It helps to raise the readability of the program.
  • While it is used to grant the specific implementation of the method which is already provided by its parent class or superclass.


  • It occurs within the class.
  • While it is performed in two classes with inheritance relationship.


  • Method overloading may or may not require inheritance.
  • While method overriding always needs inheritance.


  • In this, methods must have the same name and different signature.
  • While in this, methods must have the same name and same signature.


  • In method overloading, the return type can or can not be the same, but we just have to change the parameter.
  • While in this, the return type must be the same.

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form