Given:
public class Main{ public static void main(String[] args) { //from w w w .j ava 2s . c om // INSERT DECLARATION HERE for (int i = 0; i <= 10; i++) { List<Integer> row = new ArrayList<Integer>(); for (int j = 0; j <= 10; j++) row.add(i * j); table.add(row); } for (List<Integer> row : table) System.out.println(row); } }
Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)
B is correct.
A is incorrect because List is an interface, so you can't say new List()
, regardless of any generic types.
D, E, and F are incorrect because List only takes one type parameter.
A Map would take two, not a List.
C is tempting, but incorrect.
The type argument <List<Integer>> must be the same for both sides of the assignment.
Even though the constructor new ArrayList()
on the right side is a subtype of the declared type List on the left.