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)
Consider the following statement, which is intended to create an ArrayList named numbers that can be used to store Integer values.
ArrayList numbers = /* missing code */;
Which of the following can be used to replace /* missing code */ so that the statement works as intended?
new ArrayList()
new ArrayList
new ArrayList()
A: III only
B: I and II only
C: I and III only
D:II and III only
E: I, II, and III

Respuesta :

Answer:

B: new ArrayList()

Explanation:

When dealing with Java syntax you always need to initialize an ArrayList object with its constructor. From the options listed the only correct option would be B: new ArrayList(). This would correctly initialize the ArrayList object but is not necessarily the recommended way of doing this. The truly recommended way would be the following

ArrayList<Thing> a = new ArrayList<Thing>()

ArrayLists are simply resizable array.

  • The statement that can replace the missing code is (b) new ArrayList();
  • The statements that can replace the missing code is (c) I and III only

The syntax to create an ArrayList is:

ArrayList<Type> str = new ArrayList<Type>();

Another possible syntax is:

ArrayList var_name= new ArrayList();

The above declarations mean that: the statement that can replace the missing code is (b) new ArrayList();

While the statements that can replace the missing code is (c) I and III only

Read more about ArrayLists at:

https://brainly.com/question/18323069