aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B: Collections Self-Test Question 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 "K & B: Collections Self-Test Question" Watch "K & B: Collections Self-Test Question" New topic
Author

K & B: Collections Self-Test Question

Venkat Sidh
Ranch Hand

Joined: Sep 30, 2006
Posts: 61
Hi,

Here is the question on Page 630 & Question #12 ,



The code doesn't compile and it is fine, but if I change the code to,



And changing Person's class to



then the answer is A,B,C,E but I thought it should be A,B,C,D since Person overrides equals() and hashcode() and mutually comparable then how come duplicates are added to Set. Am I missing something here? Thanks.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I admit I puzzled over this for awhile until I spotted the error.

Note that in your definition of Person, you have the method hashcode().

However, the method you need to override from Object is hashCode().
Venkat Sidh
Ranch Hand

Joined: Sep 30, 2006
Posts: 61
Oops...good caught. I never realized it's a typo error.

[B][/B]ofcourse

Anyway its a good lesson to prepare for test.
Matthew Gerald
Greenhorn

Joined: Sep 11, 2006
Posts: 10
This had me a bit boggled as well, nice catch on that Keith.


-------------------------<br />SCJP 1.4 10/28/2006<br />SCWCD (next on the list!)
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,


annotations are not on the exam. But use it!

@Override

above your methods, and the compiler would shout out loud.

eg



will not compile, because one method is called em-two-el and the other m-twentyone.


Yours,
Bu.
[ October 28, 2006: Message edited by: Burkhard Hassel ]

all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K & B: Collections Self-Test Question