Я реализую интерфейс 'Comparable' абстрактным классом AbstractAffiliate, который расширяется абстрактным классом Abstract Faculty, который расширяется обычным классом Assistant.
После реализации метода CompareTo вКласс помощника, который был объявлен во всех перечисленных выше классах / интерфейсах, компилятор выдает эту ошибку.
Assistant.java: 1: ошибка: помощник не является абстрактным и не переопределяет абстрактный метод compareTo () в абстрактном факультетеpublic class Assistant расширяет AbstractFaculty {^ 1 error
Я пытался добавить в качестве обобщающего средства к Comparable.
Abstract Affiliate
public abstract class AbstractAffiliate implements Printable, Comparable<AbstractAffiliate>{
protected String name;
protected int age;
protected String address;
protected int phoneNumber;
protected int yearTheyCameToChapman;
/**
* Default empty AbstractAffiliate constructor
*/
public AbstractAffiliate() {
super();
age = 0;
address = " ";
phoneNumber = 0;
yearTheyCameToChapman = 0;
}
public AbstractAffiliate(String name, int age, String address, int phoneNumber, int yearTheyCameToChapman){
this.name = name;
this.age = age;
this.address = address;
this.phoneNumber = phoneNumber;
this.yearTheyCameToChapman = yearTheyCameToChapman;
}
public abstract String print();
public abstract int compareTo();
}
Abstract Faculty
public abstract class AbstractFaculty extends AbstractAffiliate{
protected int facultyId;
protected String department;
protected int yearlySalary;
protected int numberOfPapers;
/**
* Default empty AbstractFaculty constructor
*/
public AbstractFaculty() {
super();
facultyId = 0;
department = " ";
yearlySalary = 0;
numberOfPapers = 0;
}
/**
* Default AbstractFaculty constructor
*/
public AbstractFaculty(String name, int age, String address, int phoneNumber, int yearTheyCameToChapman, int facultyId, String department, int yearlySalary, int numberOfPapers) {
super(name, age, address, phoneNumber, yearTheyCameToChapman);
this.facultyId = facultyId;
this.department = department;
this.yearlySalary = yearlySalary;
this.numberOfPapers = numberOfPapers;
}
public abstract String print();
public abstract int compareTo();
}
Помощник
public class Assistant extends AbstractFaculty{
private int yearsUntilTenure;
public Assistant(){
super();
yearsUntilTenure = 0;
}
public Assistant(String name, int age, String address, int phoneNumber, int yearTheyCameToChapman, int facultyId, String department, int yearlySalary, int numberOfPapers, int yearsUntilTenure){
super(name, age, address, phoneNumber, yearTheyCameToChapman, facultyId, department, yearlySalary, numberOfPapers);
this.yearsUntilTenure = yearsUntilTenure;
}
public String print(){
return "yup";
}
public int compareTo(AbstractAffiliate affiliate){
if (this.yearTheyCameToChapman < affiliate.yearTheyCameToChapman){
return 1;
}
if (this.yearTheyCameToChapman > affiliate.yearTheyCameToChapman){
return -1;
}
else{
return 0;
}
}
}
```[enter image description here][1]
[1]: https://i.stack.imgur.com/Xdz2F.png