| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
easy Solved by 2 students
ArrayList Element Access
< Prev
Next >

Why does the following code fail to compile?

import java.util.ArrayList;
public class WrongAccess {
    public static void main(String[] args) {
        ArrayList<String> items = new ArrayList<>();
        items.add("First");
        System.out.println(items[0]);
    }
}
A

It is missing the import statement for java.util.ArrayList.

B

It incorrectly declares the ArrayList with type parameters.

C

It uses the add method with an incompatible argument.

D

It uses array index notation (items[0]) instead of the get method for ArrayLists.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy