Ask Question
14 August, 11:02

Consider the following code: public static void mystery (int a) { System. out. println ("A"); } public static void mystery (double a) { System. out. println ("B"); } public static void mystery (int a, double b) { System. out. println ("C"); } public static void mystery (double a, int b) { System. out. println ("D"); } What is output by the following? mystery (7);

+2
Answers (1)
  1. 14 August, 12:59
    0
    The output is "A"

    Explanation:

    public class Solution {

    public static void main (String args[]) {

    mystery (7);

    }

    public static void mystery (int a) { System. out. println ("A"); }

    public static void mystery (double a) { System. out. println ("B"); }

    public static void mystery (int a, double b) { System. out. println ("C"); }

    public static void mystery (double a, int b) { System. out. println ("D"); }

    }

    In the code above; mystery is defined in four different ways called method overloading. Method overloading is when same method is defined with different parameters.

    In the first case; mystery will be called if the argument is int.

    In the second case; mystery will be called if the argument is double.

    In the third case; mystery will be called if the arguments are int and double.

    In the fourth case; mystery will be called if the arguments are double and int.

    When mystery (7) is called; the mystery method requiring only int will be called and the output is "A".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following code: public static void mystery (int a) { System. out. println ("A"); } public static void mystery (double a) { ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers