45.4k views
5 votes
Consider the following statement: ArrayList newList = /* Missing Code */ Which of the following can be replaced with /* Missing Code */ so that the statement works as intended? new ArrayList; II. new ArrayList(); III. new ArrayList(); .O O I only III only I and III II and III Question: 6 I, II, and III​

User Kalpesh
by
7.6k points

1 Answer

6 votes

The correct code to create a new ArrayList and assign it to the variable newList would be:

ArrayList newList = new ArrayList();

Therefore, the missing code in the statement should be replaced with option II, which is new ArrayList();. Option III is also correct, but option I is not a valid syntax for creating a new object in Java.

So, the correct answer is II only.

User Laggel
by
7.9k points