🎴 Flashcard Mode

architecture Online Quiz - 20

Card1 / 20
Mastered0
Review0
QuestionClick to flip

public class Dec26 { public static void main(String[] args) { short a1 = 6; new Dec26().go(a1); new Dec26().go(new Integer(7)); } void go(Short x) { System.out.print("S "); } void go(Long x) { System.out.print("L "); } void go(int x) { System.out.print("i "); } void go(Number n) { System.out.print("N "); } } What is the result?

AnswerClick to flip back
A
i N
💡 Explanation:

For go(a1): short primitive widens to int, calling go(int) and printing 'i'. For go(new Integer(7)): Integer is an Object, not a primitive. It doesn't match go(Long) (Integer != Long), doesn't match go(Short) (Integer != Short), so it matches go(Number) because Integer IS-A Number. Output is 'i N'. This tests method overloading resolution with autoboxing and widening reference conversions.

Change Mode