Ask Question
10 November, 01:18

Given the following method definitions: void mystery (double a) { System. out. print ("double! "); } void mystery (int a) { System. out. print ("int! "); } What will be the output of the following code? mystery (1); mystery (1.0); Select one:

a. It is impossible to predict

b. int! double!

c. Duplicate function names results in a compiler error.

d. double! int!

+1
Answers (1)
  1. 10 November, 01:56
    0
    The correct answer to the following question is option "b".

    Explanation:

    The method having the same name but the arguments have different so it is called method overloading. It is a part of the object-oriented programming language (oops).

    In the given code we define same method two times that is "mystery () ". but in this method, we pass two different parameters. For the first time, we pass a double variable that is "a" as a parameter. In the second time, we pass an integer variable that is "a" as a parameter and in both functions, we write some codes. In the calling time, we call function two times. In first time calling we pass an integer value that is "1" and second time calling we pass double value that is "1.0". So the output of this code is "int! double!".

    That's why the option "b" is correct.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given the following method definitions: void mystery (double a) { System. out. print ("double! "); } void mystery (int a) { System. out. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers