1Z0-804 · Question #125
Given: What is the result?
The correct answer is D. The program does not compile. int compare(T obj1, T obj2) positive if obj1 greater negative if obj2 greater The compiler has a problem with the line: public boolean compare(String s1, String s2) { return s1.length() > s2.length(); error: <anonymous comparetest.CompareTest$1> is not abstract and does not…
Question
Given:
What is the result?
Exhibit
Options
- Apeach
- Bpeach
- Capple
- DThe program does not compile.
- EThe program generates an exception at runtime.
How the community answered
(23 responses)- A9% (2)
- C4% (1)
- D83% (19)
- E4% (1)
Explanation
int compare(T obj1, T obj2) positive if obj1 greater negative if obj2 greater The compiler has a problem with the line: public boolean compare(String s1, String s2) { return s1.length() > s2.length(); error: <anonymous comparetest.CompareTest$1> is not abstract and does not override abstract compare(String,String) in Comparator new Comparator<String>() { Error: compare(String,String) in <anonymous comparetest.CompareTest$1> cannot implement compare(T,T) public boolean compare(String s1, String s2) { return type boolean is not compatible with int where T is a type-variable: T extends Object declared in interface Comparator
Topics
Community Discussion
No community discussion yet for this question.
