A

Admin • 802.91K Points
Coach

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));
}
}
  • (A) No output
  • (B) Compiler error
  • (C) 10, 4.56, 10.123
  • (D) -10, -4.56, -10.123
  • Correct Answer - Option(C)
  • Views: 7
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.