KnowledgeBoat Logo
|

Computer Applications

Which of the following pairs of methods will cause a compile-time error due to incorrect method overloading?

  1. void test(int a, int b) and void test(double a, double b)
  2. void test(int a, double b) and void test(double a, int b)
  3. void test(int a, double b) and void test(int a)
  4. void test(int a) and int test(int a)

Java Method Overloading

3 Likes

Answer

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.

Answered By

1 Like


Related Questions