Consider the following statement, which is intended to create an ArrayList named a to store only elements of type Thing. Assume that the Thing class has been properly defined and includes a no-parameter constructor.
ArrayList a = /* missing code */;
Which of the following can be used to replace /* missing code */ so that the statement works as intended?
A: new Thing()
B: new ArrayList()
C: new ArrayList(Thing)
D: new ArrayList()
E: new ArrayList<>(Thing)

Respuesta :

Answer:

new ArrayList<Thing>()

Explanation:

The syntax to declare an arrayList is:

ArrayList [var-name] = new ArrayList<data-type>()

From the question;

We understand that the variable name is: a

And the data-type is: Thing

So, the ArrayList of type Thing can be defined using:

ArrayList a = new ArrayList<Thing>();

Hence:

None of the options answers the question.

ACCESS MORE