Join WhatsApp Channel Join Now
Join WhatsApp Group Join Now
Telegram Channel Join Now

Saturday, 25 December 2021

Difference Between Method Overloading and Method Overriding

In Every interview frequently asked Technical question will be difference between method overloading and method overriding. If you give exact answer for this question without confusion, then selection chances for you are 90%. If you are not able to give answer for this question (even if you give answers for some other questions) chances of your selection will be 25%. That's the important of this question in Interview.
Difference Between Method Overloading and Method Overriding in .Net/ JAVA
The concept of difference between method overloading and method overriding (in .NET or Java) is bit confuse. But here we will explain it in very simple manner, so that it helps you to remember it easily. Here we provide each difference clearly without confusion.

Before proceeding further, If you would like to get IT jobs updates or notifications at the earliest, please join with us on any one of the following channel which you prefer.



Also, 
Method Overloading:
  1. Here you can remember Method Overloading means, Methods are sharing Same Name but Parameters are different or parameters having different types and order.
  2. In Method Overloading you can Add or Extend More to Methods behavior.
  3. In Method Overloading methods must differ in the type and/or number of their parameters.
  4. The Advantage of Method Overloading is the same method call gives different outputs when called different times
  5. Method Overloading is the concept of compile time polymorphism
  6. Method overloading doesn't need Inheritance
  7. Method Overloading should be done within the class
  8. Only One class is enough for Method Overloading, No need Of Sub classes or child classes
  9. In Method Overloading, relationship is there between methods of same class
Example Program for Method Overloading:
In the following example (Method Overloading program), you can clearly observe Method names and parameters and how those are getting used. 

In Method Overloading, there will be multiple methods with the same name but with different parameters.
method overloading vs method overriding

Method Overriding:
  1. Here you can remember Method Overriding means Methods are Sharing same Name Same Parameters But in the Different class
  2. In Method overriding you can't Add or Extend More to Methods behavior, But you can change "Change" existing behavior of method.
  3. In Method Overriding Method names and parameters are same.
  4. Method Overriding is the concept of Run time polymorphism
  5. Method Overriding need inheritance
  6. Method overriding must need Class and Sub-Class or child class
  7. In Method Overriding, relationship is there between methods of super class and sub class
  8. Method Overriding always need inheritance
Example Program for Method Overriding:
In the following Method Overriding example program, you can clearly observe Method names and parameters and how those are getting used. 

In Method Overriding, there will be multiple methods with the same name and same parameter but they are in different classes.
Examples for method overloading and method overriding
If you have any queries related to "method overloading vs method overriding" concept, then comment here. We will revert you back as soon as we can.

4 comments:

Nadir zeeshan said...

1) int sum(int a,int b);
2) float sum(int a,int b);

Is this possible in method overloading? Having same parameters but different method types.

lingmaaki said...

More about....Object Oriented Programming

Ling

Anonymous said...

I really thanks to you very much ……i understood both overloading and overriding concept very well.
Regards,
Java Online Training

abc said...


I learn a lots of things here. It is an amazing post , thanks for help me.
students can learn programming on python programming tutorial
java programming language
cpp programming language

 
close

Join Telegram Channel

Join FreshersJobsUpdates - Your Job Search End Here

Click Here To Join Telegram Channel