πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 10, 4.56, 10.123

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
181
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
94%
Success Rate