|
Can anyone tell me why the below code is not executing?
<pre lang="cs">class ReturnSum
{
int sum(int a, int b)
{
return(a+b);
}
}
class SumApp12
{
public static void main(String a[])
{
ReturnSum obj=new ReturnSum();
int s1=(int)sum(50,60);
double s2=obj.sum(1.2,6.3);
System.out.println(s1+ "\t" +s2);
}
}</pre>
Akki
|
|
|
|
|
I would not expect this even to compile successfully. In the line:
double s2=obj.sum(1.2,6.3);
you are sending floating point numbers to a method that expects two integers as input parameters, and returns an integer as the result. You need to add another implementation like:
double sum(double a, double b)
{
return(a+b);
}
One of these days I'm going to think of a really clever signature.
|
|
|
|