About Question enthuware.ocpjp.v8.2.1725 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Nov 07, 2015 6:20 am
- Contact:
About Question enthuware.ocpjp.v8.2.1725 :
Shouldn't the correct answer be compare as in fourth answer, and not compareTo (second answer) as it is now.
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
Why do you think so?
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sun May 28, 2017 4:22 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
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 wrote:Why do you think so?
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
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.
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.
-
- Posts: 11
- Joined: Sun Mar 18, 2018 9:08 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
That one got me too for exactly the same reason. Sneaky sneaky..
-
- Posts: 7
- Joined: Wed Jun 06, 2018 6:46 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
+1 tricky one..
-
- Posts: 3
- Joined: Mon May 20, 2019 10:20 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1725 :
very tricky. shit...
Who is online
Users browsing this forum: No registered users and 51 guests