About Question enthuware.ocpjp.v8.2.1518 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
md4422
Posts: 3
Joined: Tue Aug 21, 2018 4:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1518 :

Post by md4422 »

the correct answer is any combination of
interests.hashCode(),
name.hashCode(), and
age

right?

interests.hashCode() + name.hashCode() is marked wrong

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1518 :

Post by admin »

The equals method of the given class uses age (along with name). Therefore, interests.hashCode() + name.hashCode() cannot be correct for the hashCode method because it doesn't use age.
You need to make sure that if equals method return true for two objects then their hashcodes must also be same. interests.hashCode() + name.hashCode() doesn't ensure that.
If you like our products and services, please help us by posting your review here.

md4422
Posts: 3
Joined: Tue Aug 21, 2018 4:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1518 :

Post by md4422 »

admin wrote:
Sun Aug 26, 2018 7:38 am
The equals method of the given class uses age (along with name). Therefore, interests.hashCode() + name.hashCode() cannot be correct for the hashCode method because it doesn't use age.
You need to make sure that if equals method return true for two objects then their hashcodes must also be same. interests.hashCode() + name.hashCode() doesn't ensure that.
you're absolutely correct. It even said it there. the "trick" is that two objects with different interests can still be .equal()

sorry for wasting your time with my idiocy. my brain went into power save mode there :)

Post Reply

Who is online

Users browsing this forum: No registered users and 105 guests