Ask Question
23 February, 01:14

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!

+2
Answers (1)
  1. 23 February, 01:29
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers