Multiple choice technology programming languages

What will be the output of the following program? public class Ques09 { public static void main(String[] args) { Integer a = null; a = new Integer(10); int b = 20; a = b; a = 30; System.out.println(a++); short s = 100; a = s; System.out.println(a--); } }

  1. The program won't compile.

  2. The program will throw a run-time exception.

  3. The program will output '31 100'

  4. The program will output '31 99'

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

The program will not compile because a = 30 assigns an int literal to an Integer reference without autoboxing, and the post-increment a++ on an Integer reference is followed by assignment a = s which mixes operations ambiguously. Java requires explicit boxing or proper reference handling.

AI explanation

'The program won't compile' is correct. The fatal line is a = s; where s is a short and a is an Integer. Java autoboxing only converts a primitive directly to its own matching wrapper type (short → Short), not to a different wrapper via an implicit widening step (short → int → Integer). Since there's no direct short-to-Integer conversion and Java won't chain a widening conversion with a boxing conversion in one implicit step, a = s; is a compile-time type error. Everything before it (a = new Integer(10), a = b where b is int → autoboxes fine to Integer, a = 30, a++) is legal, so the failure is specifically triggered by the short-to-Integer assignment, ruling out the runtime-exception and output-producing options.