I have a subclass that declares all of the methods in my abstract superclass, yet it still gives me an error stating that my class isn't abstract. I cannot figure out why this error is getting thrown.
The specific error I'm getting is
PhoneBookEntry.java:1: error: PhoneBookEntry is not abstract and does not override abstract method compareTo(Object) in Comparable
My code in question:
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 > 0)
return 1;
else if(first < 0)
return -1;
else
if(num > 0)
return 1;
else if(num < 0)
return -1;
else
return 0;
}
}
And my subclass:
public class PhoneBookEntry extends PhoneNumber
{
public PhoneBookEntry(String firstName, String lastName, int number)
{
super(firstName, lastName, number);
}
public String getLastName()
{
return lastName;
}
public String getFirstName()
{
return firstName;
}
public int getNumber()
{
return number;
}
public int compareTo(PhoneNumber other)
{
super.compareTo(other);
}
}