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

Samuel Fernandes

Total Post:38

Points:190
Posted by  Samuel Fernandes
Java 
 1866  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-30-2015 02:43:53 AM

Answer

NEWSLETTER

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