QuestionQ206

Working with Selected Classes from the Java API

Given:

Question Image

What is the output?

  • A true
  • B false
  • C -1
  • D 0
Explanation

List.indexOf returns -1 when no element is equal to the search object. Because Product does not override equals, the two distinct Product instances are not equal despite having the same id and name values.

Community Discussion

No comments yet. Be the first to start the discussion!