QuestionQ131

Working with Selected Classes from the Java API

Given:

Question Image

And the code fragment:

Question Image

Which code fragment, when inserted on line 14, allows the code to print Mike Found?

  • A
  • B
  • C
  • D
Explanation

ps contains the same Patient instance referenced by p2, so ps.indexOf(p2) returns index 0. Since Patient does not override equals, a separate new Patient("Mike") instance is not equal to the stored object merely because it has the same name.

Community Discussion

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