Ctrl K
Java · Junior · Coding

There's a class Point with two integer fields, x and y. Override its equals and hashCode methods so that points with the same coordinates are considered equal and work correctly as keys in a HashMap.

~15 min by voice

How to approach it

The interviewer wants to see whether you understand the equals/hashCode contract and how a HashMap looks up keys: first it picks a bucket by hashCode, then it compares using equals. Plus basic care: overriding rather than overloading, handling null and checking the type, immutable fields.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWhat is the equals and hashCode contract, and what happens if you break it? Junior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~15 min