Page 1 of 1
About Question enthuware.ocpjp.v8.2.1098 :
Posted: Wed Aug 03, 2016 11:19 am
by badbishop
In fact, all the answers are valid implementations, as they have no compilation issues.
The question should be rephrased to refer to suitability for usual equality establishment operations. Or, say, one could add @Override annotation to each possible answer.
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Wed Aug 03, 2016 11:36 am
by admin
This is as per the convention followed by the real exam. The real exam questions explicitly say "compiles correctly" or "runs without exception" when they refer to compilation or runtime issues. It doesn't use the word "valid" for compilation or execution. It uses this word for when the code is inappropriate for some or the other reason.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Thu Apr 26, 2018 11:52 pm
by shamran99
Hi,
Please explain the bolded part. Thanks!
It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified.
Regards,
Shamran
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Fri Apr 27, 2018 12:11 am
by admin
If you modify the value of any field that is used in the equals method to compare, then the value returned by equals may change. For example, if your equals method compares an int instance variable of two objects then if you change the value of that int variable of one object then equals may return a different value.
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Wed May 02, 2018 8:35 am
by shamran99
Thanks!
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Thu Feb 20, 2020 9:15 am
by bvrulez
I don't want to criticize the question and answers but I wanted to check if I understand it right that in this (correct) case the equals method returns true just in this one case that the two references are pointing to the same object.
Re: About Question enthuware.ocpjp.v8.2.1098 :
Posted: Thu Feb 20, 2020 10:22 am
by admin
That's right.