Overloading Concepts - rahul00773/JavaConcepts GitHub Wiki

OverLoading

Two methods are said to be overloaded if and only if both methods having the same name but different argument types.

In the C language method overloading concept is not available hence we can’t declare multiple methods with the same name but different argument types.

If there is a change in argument type compulsory we should go for a new method name which increases the complexity of programming.

In C: abs(int I) labs(long l) fabs(float f)

But In java, we can declare multiple methods with the same name but different argument types. Such types of methods are called overloaded methods.

abs(int I) abs(long l) abs(float f)

Having overloading concept in java reduced complexity of programming

class Test{

public void m1(){

}

public void m1(int i){

}

public void m1(double i){

}

}

class demo{

public static void main(String[] args) {

Test T = new Test();

T.m1();

T.m1(10);

T.m1(10.5);

} }

In overloading method resolution always take care by the compiler based on the reference type. Hence overloading is also considered as Compile time polymorphism or static polymorphism or early binding.