Why is method overloading not possible by changing the return type in java?

Solution:

In Java, method overloading is not possible by changing the return type of the program due to avoid the ambiguity.

class Adder{  
static int add(int a,int b){return a+b;}  
static double add(int a,int b){return a+b;}  
}  
class TestOverloading3{  
public static void main(String[] args){  
System.out.println(Adder.add(11,11));//ambiguity  
}}  

Output:

Compile Time Error: method add(int, int) is already defined in class Adder
0 answers