Thursday, 29 January 2015

Why Method Overloaing is not possible by changing the return type of method?

By 11:12
In java, method overloading is not possible by changing the return type of the method because there may occur ambiguity. Let's see how ambiguity may occur: because there was problem: 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 } } Output::::: int result=obj.sum(20,20); //Here how can java determine which sum() method should be called

0 comments:

Post a Comment