About Question enthuware.ocpjp.v8.2.1725 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
morpana
Posts: 1
Joined: Sat Nov 07, 2015 6:20 am
Contact:

About Question enthuware.ocpjp.v8.2.1725 :

Post by morpana »

Shouldn't the correct answer be compare as in fourth answer, and not compareTo (second answer) as it is now.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by admin »

Why do you think so?
If you like our products and services, please help us by posting your review here.

nieckq
Posts: 1
Joined: Sun May 28, 2017 4:22 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by nieckq »

admin wrote:Why do you think so?
Because, as it even says in the answer, Comparable has the compareTo(T t) method, and the Comparator makes you implement the compare(Obj obj1, Obj obj2) method. In this case because Person does not implement comparable, we want to sort the collection using a Comparator. Hence we use the compare(Obj obj1, Obj2 obj) method and not compareTo(T t).

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by admin »

If you look closely, Option 2 does use compare method (and not compareTo) to compare Person objects.

The compareTo method is used to compare only the the dob field inside the implementation of the compare method. This has nothing to do with Comparator. String class implements Comparable and not Comparator.

String class does not have compare method and that is why option 4 is incorrect.
If you like our products and services, please help us by posting your review here.

Wesley
Posts: 11
Joined: Sun Mar 18, 2018 9:08 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by Wesley »

That one got me too for exactly the same reason. Sneaky sneaky..

d0wnvk@gmail.com
Posts: 7
Joined: Wed Jun 06, 2018 6:46 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by d0wnvk@gmail.com »

+1 tricky one..

tugrulkarakaya
Posts: 3
Joined: Mon May 20, 2019 10:20 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1725 :

Post by tugrulkarakaya »

very tricky. shit...

Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests