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 } }
Post:807
Points:4035Why 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: