Question 128 / 297:  What is the result of compiling and running the following code?
public class Tester {

static void call(Long x, Long y) {

System.out.print("Long x, Long y");

}

static void call(int... x) {

System.out.print("int... x");

}

static void call(Number x, Number y) {

System.out.print("Number x, Number y");

}

public static void main(String[] args) {

int val = 3;

call(val, val);

}

}

A  Long x, Long y
B  int... x
C  Number x, Number y
D  Compilation error
E  An exception is thrown at run time
<< First < Previous Next > Last >>
Explanation:

Var-args is always chosen last.

You cannot widen then autobox (cannot widen from int to long then autobox to Long), BUT you can autobox then widen (autobox to Integer then widen to Number, Integer extends Number) therefore “Number x, Number y” is printed

Exam Home Page
Ask
Madison Christian
Start Quiz
Brooke Delaney
Start Exam
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>