Multiple choice technology web technology

What is the output for the below code ? public class Test { public static void main(String[] args) { List list = new ArrayList(); list.add(0, 59); int total = list.get(0); System.out.println(total); } }

  1. Compile Properly but Runtime Exception

  2. Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();

  3. 59

  4. Compile time error, because can't add primitive type in List.

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

Java autoboxes the primitive int 59 to Integer when added to the ArrayList. Then get(0) returns the Integer object, which autounboxes to int when assigned to the primitive variable 'total'. The code compiles and runs successfully, outputting 59. No explicit casting or type conversion is needed thanks to autoboxing/autounboxing.