Forums Register Login

equals vs hashCode (K&B Exam 6)

+Pie Number of slices to send: Send
K&B Exam SCJP6 quiz 1 question 52:



My code that prints "false true" is below. Hashcodes are not equal, equals returns true. But equal objects must have equal hashcodes.
So conclusion: only "C" is the correct answer ("D" is not correct opposed to what it says in the mock exam). Am I right or do I miss something?

+Pie Number of slices to send: Send
Yes you are right, this is an error in the mock exam. This has been asked before too

And welcome to javaranch...
+Pie Number of slices to send: Send
 

Ankit Garg wrote:Yes you are right, this is an error in the mock exam. This has been asked before too

And welcome to javaranch...



Thanks
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 966 times.
Similar Threads
equal(Object o) doubt
About equals() and hashcode() contracts
Question on hashCode() & equals() from master exam 1
Possible Wrong answer in k&b Master Exam
Doubt with hasCode() contract
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:10:53.