Given: class Eggs { int doX(Long x, Long y) { return 1; } int doX(long... x) { return 2; } int doX(Integer x, Integer y) { return 3; } int doX(Number n, Number m) { return 4; } public static void main(String[] args) { new Eggs().go(); } void go () { short s = 7; System.out.print(doX(s,s) + " "); System.out.println(doX(7,7)); } }

  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 3 3

  6. 4 3


Correct Option: C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 1 1 - This option is incorrect because the first call to doX passes two short values (s), and the method with parameters Integer x, Integer y is not applicable. The second call to doX passes two int values (7), and the method with parameters int doX(long... x) is not applicable. Therefore, the output is not 1 1.

Option B) 2 1 - This option is incorrect because the first call to doX passes two short values (s), and the method with parameters Integer x, Integer y is not applicable. The second call to doX passes two int values (7), and the method with parameters int doX(long... x) is not applicable. Therefore, the output is not 2 1.

Option C) 3 1 - This option is correct. The first call to doX passes two short values (s), and the method with parameters int doX(Number n, Number m) is applicable because short is widened to int, and Number is a superclass of Integer. Therefore, the output is 3. The second call to doX passes two int values (7), and the method with parameters int doX(long... x) is applicable because int can be autoboxed to long. Therefore, the output is 1. The overall output is 3 1.

Option D) 4 1 - This option is incorrect because the first call to doX passes two short values (s), and the method with parameters Integer x, Integer y is not applicable. The second call to doX passes two int values (7), and the method with parameters int doX(long... x) is not applicable. Therefore, the output is not 4 1.

Option E) 3 3 - This option is incorrect because the first call to doX passes two short values (s), and the method with parameters int doX(Number n, Number m) is applicable because short is widened to int, and Number is a superclass of Integer. Therefore, the output is 3. The second call to doX also passes two int values (7), but it does not match any of the available methods. Therefore, the output is not 3 3.

Option F) 4 3 - This option is incorrect because the first call to doX passes two short values (s), and the method with parameters int doX(Number n, Number m) is applicable because short is widened to int, and Number is a superclass of Integer. Therefore, the output is 3. The second call to doX also passes two int values (7), but it does not match any of the available methods. Therefore, the output is not 4 3.

The correct answer is Option C) 3 1. This option is correct because the first call to doX is resolved to the method int doX(Number n, Number m), and the second call to doX is resolved to the method int doX(long... x).

Find more quizzes: