WHY METHOD OVERLOADING IS NOT POSSIBLE BY CHANGING THE RETURN TYPE IN JAVA?

Samuel Fernandes

Total Post:0

Points:0
Posted by  Samuel Fernandes
Java 
 2411  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

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

    n java, method overloading is not possible by changing the return type of the method because there may occur ambiguity.here is an example which state how ambiguity might occur:


    here how java determine which method to call 

    class Calculation3{  
      int sum(int a,int b){System.out.println(a+b);}  
      double sum(int a,int b){System.out.println(a+b);}  
      
      public static void main(String args[]){  
      Calculation3 obj=new Calculation3();  
      int result=obj.sum(20,20); //Compile Time Error  
      
      }  
    }   

      Modified On Mar-27-2018 11:27:26 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!