aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrong Answer in Master Exam? [equals() and hashCode() Contract] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrong Answer in Master Exam? [equals() and hashCode() Contract]" Watch "Wrong Answer in Master Exam? [equals() and hashCode() Contract]" New topic
Author

Wrong Answer in Master Exam? [equals() and hashCode() Contract]

Mana Lesar
Greenhorn

Joined: Apr 12, 2010
Posts: 25
There is a question in Master Exam A mock test:



For me the only correct answer is C, and MasterExam claims that correct answers are C and D. For me answer D is wrong, cause we can imagine the situation where we have two SortOf objects with the following instance variables values:

A:
length=2;
bal=3;
rate=4;

B:
length=2;
bal=4;
rate=3;

Given the equals method from D answer both object are considered equal, cause 2*3*4=2*4*3, but theirs hashCode differs cause 2*3 != 2*4, so the contract is not fulfilled. Is it rather obvious mistake in MasterExam or somehow i get it wrong?
Rajeev Rnair
Ranch Hand

Joined: Mar 22, 2010
Posts: 308

I think C is the only correct answer!
For D to be correct the 'rate' has to be declared as a final variable



SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
Mana Lesar
Greenhorn

Joined: Apr 12, 2010
Posts: 25
Exactly.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Wrong Answer in Master Exam? [equals() and hashCode() Contract]