Which of the following pairs of methods will cause a compile-time error due to incorrect method overloading?
- (a)void test(int a, int b) and void test(double a, double b)
- (b)void test(int a, double b) and void test(double a, int b)
- (c)void test(int a, double b) and void test(int a)
- (d)void test(int a) and int test(int a)
Show SolutionHide Solution↓
void test(int a) and int test(int a)
Reason — In Java, method overloading depends on the method's name and its parameter list (number or type of parameters). The return type alone is not considered for method overloading. So, void test(int a) and int test(int a) have the same name and same parameter list, which causes a compile-time error because they differ only in return type, not in parameters.