读书人

超类、子类接口实现泛型数组排序综合

发布时间: 2013-02-24 17:58:57 作者: rapoo

超类、子类接口实现,泛型数组排序综合使用遇到的问题
我实现了几个类:
Person、Employee extends Person、Student extens Person、Manager extends Employee
在书上看到,实现接口的方法:
1、将类声明为实现给定的接口;
2、对接口中的所有方法进行定义。
我在声明的时候(Class Person implements comparable)
报错:The type Person must implement the inherited abstract method Comparable.compareTo(Object),于是我认为无需声明,所以去掉了声明的部分。

在Person类中定义接口的compareTo方法:

                            
[解决办法]
引用:
2、对接口中的所有方法进行定义。
我在声明的时候(Class Person implements comparable)
报错:The type Person must implement the inherited abstract method Comparable.compareTo(Object),于是我认为无需声明,所以去掉了声明的部分。
报错……


必须声明,如果person类不想实现这个方法,直接把Persion类定义成Abstract就行了

读书人网 >Eclipse开发

热点推荐