Topic:   Why is method overloading not possible by changing the return type in java?
Mar 03, 2021 11:03 1 Replies 119 Views RANJIT

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

Prev Next
Topic Replies (1)
  1. 1
    idnkx user

    ROHAN

    In Java, method overloading is not possible by changing the return type of the program due to avoid the ambiguity.
    1. class Adder{
    2. static int add(int a,int b){return a+b;}
    3. static double add(int a,int b){return a+b;}
    4. }
    5. class TestOverloading3{
    6. public static void main(String[] args){
    7. System.out.println(Adder.add(11,11));//ambiguity
    8. }}

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect