Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<int> marks = new ArrayList<>();
marks.add(90);
System.out.println(marks);
}
}
- A ArrayList needs a size
- B Generic type arguments must be reference types; use List<Integer> and let autoboxing convert the ints Correct
- C add cannot take 90
- D List must be imported twice
Correct Answer: Option B
javac: "unexpected type – required: reference, found: int".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!