the correct answer is any combination of
interests.hashCode(),
name.hashCode(), and
age
right?
interests.hashCode() + name.hashCode() is marked wrong
About Question enthuware.ocpjp.v8.2.1518 :
Moderator: admin
-
- Posts: 3
- Joined: Tue Aug 21, 2018 4:44 am
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1518 :
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 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.
-
- Posts: 3
- Joined: Tue Aug 21, 2018 4:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1518 :
you're absolutely correct. It even said it there. the "trick" is that two objects with different interests can still be .equal()admin wrote: ↑Sun Aug 26, 2018 7:38 amThe 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.
sorry for wasting your time with my idiocy. my brain went into power save mode there
Who is online
Users browsing this forum: No registered users and 105 guests