Multiple choice

What will be the output of the following code? import java.util.*; public class Hello { public static void main(String arg[]) { ArrayList<Integer> list= new ArrayList<Integer>(); list.add(10); int total=list.get(0); System.out.println(total); } }

  1. Compile error

  2. 10

  3. Run time error

  4. Zero

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

The code creates an ArrayList, adds 10, retrieves index 0, and prints it. This compiles and runs successfully, outputting 10. ArrayList stores Integer objects; get() returns an Integer which is auto-unboxed to int. No compilation or runtime errors occur.