IGNOU MBA Assignment, Solved IGNOU MBA Assignments

Explain the difference between overloading & overriding?

Overloading takes place when more than one method in the same class share the same name. This could mainly happen when at least one of the following points is valid:
1.) The number of parameters differs for the methods
2.) The parameter types are different.

Overloading Example:
void calculate(float x){
}
void calculate(double x){
}
void calculate(int x){
}

Overriding is totally different. If a child class needs a different definition for the inherited method, then that method could be redefined in the child class. This will be regarded as overriding. An overridden method would’ve exactly the same method name, return type, number of parameters, and kinds of parameters since the method in the parent class, and the sole distinction will be the definition of the method.

Example:
public class BaseClass{
public void methodToOverride(){
//Some code here
} }public class DerivedClass extends BaseClass{
public void methodToOverride() {
//Some new code here
} }

1. In overloading, there exists a relationship between methods found in the same class where by in overridding, there is relationship between a parent class method and subclass method.
2. In overloading, seperate methods share exactly the same name while in overridding, child class method replaces the parent class.
3. Overloading needs to have different method signatures where as overriding needs to have same signature.

Let’s sum up the dissimilarities between overloading and overriding. When overloading, you have to change either the type or the number of parameters for a method which belongs to the same class. But, overriding a method implies that a method inherited from a base class is what’s being altered.

What is method Overloading?

Explain the concept of overriding in Java?