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

DWQA QuestionsCategory: JavaWhy is method overloading not possible by changing the return type in java?
Editor Staff asked 11 months ago

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

1 Answers
Editor Staff answered 11 months ago

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
}}
Test it Now
Output:
Compile Time Error: method add(int, int) is already defined in class Adder