我有一个子类声明我的抽象超类中的所有方法,但它仍然给我一个错误,说明我的类不是抽象的.我无法弄清楚为什么会抛出这个错误.
我得到的具体错误是
PhoneBookEntry.java:1:错误:PhoneBookEntry不是抽象的,并且不会覆盖Comparable中的抽象方法compareTo(Object)
我的代码有问题:
public abstract class PhoneNumber implements Comparable
{
protected String firstName, lastName;
protected int number;
public PhoneNumber(String firstName, String lastName, int number)
{
this.firstName = firstName;
this.lastName = lastName;
this.number = number;
}
public abstract String getLastName();
public abstract String getFirstName();
public abstract int getNumber();
public int compareTo(PhoneNumber other)
{
int last = other.lastName.compareTo(lastName);
int first = other.firstName.compareTo(firstName);
int num = other.number - number;
if(last > 0)
return 1;
else if(last < 0)
return -1;
else
if(first …Run Code Online (Sandbox Code Playgroud)