A. wrong
public int compare(T o1, T o2) - must be implemeted
B. wrong
Because it missed generic type parameter
should have Object type arguments
public int compare (Object obj1, Object obj2)
C. correct
Anonymous with interface implementation
Generic type parameter is String and method compare with String arguments
D. wrong
wrong return type
answer: AC
A and C are the same
Anonymous with interface
as a result there is a valid comparable implementation
D failed
wrong return type
B failed
should have raw type arguments
public int compare (Object obj1, Object obj2) {
Correct answer is C .
//A is invalid because :The type new Comparator<String>(){} must implement the inherited abstract method Comparator<String>.compare(String, String)
//B is invalid because : The type Comps must implement the inherited abstract method Comparator.compare(Object, Object)
//D is invalid because : The return type is incompatible with Comparator.compare(Object, Object) and Illegal modifier for the local class Comps; only abstract or final is permitted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
3 weeks, 5 days agoASPushkin
4 months, 1 week agoASPushkin
4 months, 1 week agognilapon.ebenezaire
6 months agod7bb0b2
1 year, 1 month agoStavok
1 year, 7 months agoMukes877
1 year, 7 months agopikosss
1 year, 10 months agoTADIEWA
2 years ago