Friday, 13 March 2015

Difference Between Method Overloading and Method Overriding in .Net/ JAVA

                In Every interview frequently asked Technical question is difference between method overloading and method overriding. If you given exact answer for this question without confusion , Then selection chances are 90%. If you didn’t give answer for this question (even if you give answers for some other questions) chances of selection is 25%. That’s the important of this question in Interview.
difference-between-method-overloading-and-method-overriding

                The concept of difference between method overloading and method overriding in .net/ java is bit confused concept. But here we provide very easiest way to remember. Here we provide each difference clearly without confusion.

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 Method Overloading example program, you can clearly observe Method names and parameters, how those are using. That is Same Method name Different parameters
method-overloading-example-program

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 Overloading:
In the following Method Overriding example program, you can clearly observe Method names and parameters, how those are using. That is same Method name and same parameters but different classes.
Method-overloading-images-example-program

If you have any queries related to “difference between method overloading and method overriding” concept comment here.

You may search in Google also:
difference between method overloading and method overriding, method overloading and method overriding, method overloading V/S method overriding, what is method overloading, what is method overriding, method overloading in .Net, method overloading in JAVA, method overloading in .Net, method overloading in JAVA.

4 comments:

 
Copyright © . Freshers Junction - Posts · Comments
Theme Template by Freshers Junction · Powered by Blogger