200+ câu trắc nghiệm Lập trình Java cơ sở có đáp án - Phần 7

Cho class như sau:java1: public interface Comparable { 2: int compareTo(Employee other);3: }4: class Employee implements Comparable { 5: public int compareTo(Object other) {6: return 0;7: }8:

4/30

Cho class như sau:

1: public interface Comparable {

2: int compareTo(Employee other);

3: }

4: class Employee implements Comparable {

5: public int compareTo(Object other) {

6: return 0;

7: }

8: }

Chương trình trên sai ở dòng nào?

1

2, 4

5

8

Giải thích

Chọn đáp án C (Lớp Employee implement Comparable nhưng lại override compareTo(Object other) thay vì compareTo(Employee other))