OCA Java SE 8 Core Java APIs - OCA Mock Question Core Java APIs 3-7








Question

Which of the following are true? (Choose all that apply)

  1. Two arrays with the same content are equal via using the equals method.
  2. Two ArrayLists with the same content are equal via using the equals method.
  3. If you call remove(0) using an empty ArrayList object, it will compile successfully.
  4. If you call remove(0) using an empty ArrayList object, it will run successfully.
  5. None of the above.




Answer



B, C.

Note

An array in Java does not override equals() and so we cannot use equals method on array to compare two array objects.

ArrayList does override equals() and equals method returns true if two array list object have the same elements in the same order.

The compiler does not know when an index is out of bounds.

The code will throw an exception at runtime, though.