Ask Question
26 August, 16:54

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!

+4
Answers (1)
  1. 26 August, 19:31
    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?
Find 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 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