What is the result?
A. many
B. a few
C. Compilation fails.
D. The output is not predictable.
E. An exception is thrown at runtime.
Answer:
C is correct, compilation fails. The var-args declaration is fine, but invade takes a short,
so the argument 7 needs to be cast to a short. With the cast, the answer is B, 'a few'.
A, B, D, and E are incorrect based on the above. (Objective 1.3)
==
A. many
B. a few
C. Compilation fails.
D. The output is not predictable.
E. An exception is thrown at runtime.
Answer:
C is correct, compilation fails. The var-args declaration is fine, but invade takes a short,
so the argument 7 needs to be cast to a short. With the cast, the answer is B, 'a few'.
A, B, D, and E are incorrect based on the above. (Objective 1.3)
==
class Alien { String invade(short ships) { return "a few"; } String invade(short... ships) { return "many"; } } class Defender { public static void main(String [] args) { System.out.println(new Alien().invade(7)); } }
No comments:
Post a Comment