Case 1 For Overloading - rahul00773/JavaConcepts GitHub Wiki

Automatic Promotion in overloading:

While resolving overloaded methods if exact matched method is not available then we won’t get any compile time error immediately. First it will prompt argument to the next level and check whether matched method is available or not.

If matched method is available then it will be considered. And if the matched method is not available then compiler prompts argument once again to the next level. This process will be continued until all possible promotions. Still if the matched method is not available then we will get compile time error.

The Following are all possible promotions in overloading.

Byte - Short -> Int -> Long > Float .->Double

Char -> int

This process is called automatic promotion in overloading.

class Test{

public void m1(int I) {

}

public void float(float f){

} }

class T{ public static void main(String[] args){

Test t = new Test();

t.m1(10);

t.m1(10.5f);

t.m1(‘a’);

t.m1(10.5l);

t.m1(10.5); //Can’t find symbol location class Test

} }