A
Q. What is the output of the below Java program that tries to overload a method "abs"?
Code:
public class MyAbs
{
static int abs(int a)
{
return a<0?-a:a;
}
static float abs(float b)
{
return b<0?-b:b;
}
static double abs(double c)
{
return c<0?-c:c;
}
public static void main(String[] args)
{
int a=-10;
float b=-4.56f;
double c=-10.123;
System.out.println(MyAbs.abs(a) + ", " + MyAbs.abs(b) + ", " + MyAbs.abs(c));
}
}
{
static int abs(int a)
{
return a<0?-a:a;
}
static float abs(float b)
{
return b<0?-b:b;
}
static double abs(double c)
{
return c<0?-c:c;
}
public static void main(String[] args)
{
int a=-10;
float b=-4.56f;
double c=-10.123;
System.out.println(MyAbs.abs(a) + ", " + MyAbs.abs(b) + ", " + MyAbs.abs(c));
}
}
- Correct Answer - Option(C)
- Views: 7
- Filed under category Java
- Hashtags:
Discusssion
Login to discuss.