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.
In the following example (Method Overloading program), you can clearly observe Method names and parameters and how those are getting used.
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,
- Click Here to Enter Your Email ID
- Check Your Email To Activate Confirmation Link
Method Overloading:
- Here you can remember Method Overloading means, Methods are sharing Same Name but Parameters are different or parameters having different types and order.
- In Method Overloading you can Add or Extend More to Methods behavior.
- In Method Overloading methods must differ in the type and/or number of their parameters.
- The Advantage of Method Overloading is the same method call gives different outputs when called different times
- Method Overloading is the concept of compile time polymorphism
- Method overloading doesn't need Inheritance
- Method Overloading should be done within the class
- Only One class is enough for Method Overloading, No need Of Sub classes or child classes
- In Method Overloading, relationship is there between methods of same class
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 Overriding:
- Here you can remember Method Overriding means Methods are Sharing same Name Same Parameters But in the Different class
- In Method overriding you can't Add or Extend More to Methods behavior, But you can change "Change" existing behavior of method.
- In Method Overriding Method names and parameters are same.
- Method Overriding is the concept of Run time polymorphism
- Method Overriding need inheritance
- Method overriding must need Class and Sub-Class or child class
- In Method Overriding, relationship is there between methods of super class and sub class
- Method Overriding always need inheritance
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.
4 comments:
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.
More about....Object Oriented Programming
Ling
I really thanks to you very much ……i understood both overloading and overriding concept very well.
Regards,
Java Online Training
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
Post a Comment