SCJP Module-9 Question-11


 

SCJP Module-9 Question-11

The sample program given below will test your understanding of inserting data into the object of the ArrayList class and printing them using for loop.

The sample program given below will test your understanding of inserting data into the object of the ArrayList class and printing them using for loop.

Given below the sample code :

public class Check{
public static void main(String... args) {
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(3);
alist.add(12);
alist.add(21);
alist.add(30);
for(int a : alist)
System.out.println(a);
}
}

What will be the output of the above code ?

1. compile error

2. 3 12 21 30

3. 0 0 0 0

4. 30 21 12 3

Answer

(2)

Ads