Wednesday 13 September 2017

Difference between method overloading and method overriding in Java

Do you know what is method overloading and method overriding? What is the Difference between method overloading and method overriding in Java?


So, Here you get the answer to all the questions. There are lots of difference between method overloading and overriding. Some of them are as follows:-


  • Method overloading is used to increase the readability of the program whereas, Method overriding is used to provide the implementation of the method that is already provided by its parent class.
  • Method overloading is performed within class whereas, Method overriding is performed with the help of two classes that have IS-A relationship.
  • In case of method overloading, the parameter must be different whereas, In case of method overriding, the parameter must be same.
  • Method overloading is the example of compile time polymorphism whereas, Method overloading is the example of compile time polymorphism.

From Example, you can easily be able to understand all the differences between method overloading and method overriding.

Example Of Method Overloading:



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


Example Of Method Overriding:

class RidingTest{  
void display()
{
System.out.println("eating...");
}  
}  
class Demo extends RidingTest{  
void display()
{
System.out.println("eating bread...");
}  

It is all about method overloading and overriding, I hope you all understand the concept of method overriding and method overloading.

1 comment:

  1. is there a typo "Method overloading is the example of compile time polymorphism whereas, Method overloading is the example of compile time polymorphism."

    ReplyDelete