What is the result?

Given the code fragment: What is the result?

Given the code fragment: What is the result?

A.
Compilation fails due to an error on line 1.

B.
An exception is thrown at run time due to error on line 3

C.
An exception is thrown at run time due to error on line 4

D.
1002



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Kevin

Kevin

C

list.size() outputs 2 as there are 2 elements (i.e. 1001 and 1002)

This means System.out.println(list.get(2)) which produces an java.lang.IndexOutOfBoundsException at run time because the elements are at position 0 and 1