nerdexam
Oracle

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…

Java Class Design

Question

Given:

What is the result?

Exhibit

1Z0-804 question #125 exhibit

Options

  • Apeach
  • Bpeach
  • Capple
  • DThe program does not compile.
  • EThe program generates an exception at runtime.

How the community answered

(23 responses)
  • A
    9% (2)
  • C
    4% (1)
  • D
    83% (19)
  • E
    4% (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

#String#compilation#immutability#type mismatch

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice