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

Category: JavaWhy is method overloading not possible by changing the return type in java?
Editor">Editor Staff asked 2 years ago

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

1 Answers
Editor">Editor Staff answered 2 years 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