Multiple choice technology programming languages

Which of the following methods will be invoked when the call is-- show(10L);

  1. show(float f){ }

  2. show(int i){ }

  3. show(double d){ }

  4. none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

10L is a long. Method overloading chooses the most specific applicable method. show(float) is selected over show(double) because float is more specific - both accept long via widening, but float is chosen as the narrower type.

AI explanation

When Java resolves an overloaded call like show(10L), it looks for a method whose parameter type the argument can be widened to, since there's no long overload here. long can widen to both float and double, so both overloads are technically applicable. Java's overload resolution picks the most specific applicable method, and float is considered more specific than double in the widening chain (float can widen further to double, but not vice versa), so show(float) wins. show(int) is not viable at all because long cannot implicitly narrow to int.