Multiple choice technology programming languages

What will be output for the following program? public class BoxingTest { public static void main(String[] args) { byte b = 10; method(b); } static void method(int i){ System.out.println("Primitive Type call"); } static void method(Integer i){ System.out.println("Wrapper Type Call"); } }

  1. Wrapper Type Call

  2. Primitive Type Call

  3. Compiler Error

  4. Compiles fine, throws runtime exception

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

The variable b is of primitive type byte. Widening is preferred over autoboxing, so JVM chooses the primitive type method over the wrapper type method by widening byte to int. Thus, method(int) is executed, printing "Primitive Type call". Autoboxing to Integer is not selected because widening takes precedence.