File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock doubt, a Q about equals contract Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock doubt, a Q about equals contract" Watch "Mock doubt, a Q about equals contract" New topic
Author

Mock doubt, a Q about equals contract

Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
The following is from K & B Mock exam 1

if the output is "x = 1111", which of the following will always be true ?

All my answers counted as wrong, and the correct answer is
x2.equals(x1) == true;

This is an error isn't it, specially this one should always be false
if it become true, then the equals() contract will not be applied.


SCJP 5
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
I think this must be
x7.equals(x8) == true or x8.equals(x7) == true;
x2.equals(x1) may results to true or false.


~Sanjeev Singh<br />SCJP 1.5
Costa lamona
Ranch Hand

Joined: Sep 24, 2006
Posts: 102
Thanks

Originally posted by Sanjeev Kumar Singh:
I think this must be
x2.equals(x1) may results to true or false.


Actually, I beleive it can be true because the contrapositive of one of
the statments in the hashCode() contract is

if x.hashCode() != y.hashCode() returns true, then x.equals(y) must return false.

K & B on page 534.

Do you agree ?
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
I revisited the hashCode() and equal() contract.I think I have given wrong explanation.

if x.hashCode() != y.hashCode() returns true, then x.equals(y) must return false.

Yes I agree on this.So it is not neccessary that x.equals(y)must not return true.
Now coming to the original question

x3.hashCode()==x4.hashCode() must return true and
x5.hashCode()==x6.hashCode() must return true
 
wood burning stoves
 
subject: Mock doubt, a Q about equals contract
 
Similar Threads
Question from Mock exam
Master Exma question
Doubt in one question of K & B Mock exam on CD
HashCode and Equals Contract Question from Master Exam Learner Key
Can't Understand... K&B Mock Exam