nerdexam
Oracle

1Z0-851 · Question #164

1Z0-851 Question #164: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-851 to reveal the answer and full explanation for question #164. The question stem and answer options stay visible for context.

Question

Given: public class Person { private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; } public boolean equals(Object o) { if (! (o instanceof Person)) return false; 19, Person p = (Person)o; return age == p.age && name.equals(p.name); } } What is the appropriate definition of the hashCode method in class Person?

Options

  • Areturn super.hashCode();
  • Breturn name.hashCode() + age * 7;
  • Creturn name.hashCode() + comment.hashCode() / 2;
  • Dreturn name.hashCode() + comment.hashCode() / 2 - age * 3;

Unlock 1Z0-851 to see the answer

You've previewed enough free 1Z0-851 questions. Unlock 1Z0-851 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-851 Practice