Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:27:50+00:00 2026-05-27T04:27:50+00:00

I have an abstract class Person and and interface comparable, which is also used

  • 0

I have an abstract class Person and and interface comparable, which is also used for some other part of the program. Currently I have a method compareTo() in Person. When I try to compile, I get :

The type Student must implement the inherited abstract method 
 Comparable<Person>.compareTo(Person, Person)

What exactly do I have to do? I don’t wont to implement this method in any of the subclasses, because I need this method for all of them, Student, Tutor, Professor, etc… Is there a better way of doing this?

Interface:

interface Comparable<Element> {
    public int compareTo(Element nodeA, Element nodeB);
}

Abstract class Person:

abstract class Person implements Comparable<Person> {

    protected String name;

    public Person(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String newName) {
        name = newName;
    }
    public String toString() {
        return name;
    }

    public int compareTo(Person personB) {
        int comp = this.name.compareTo(personB.getName());
        return comp;
    }
}

And class Student

class Student extends Person implements Comparable<Person> {

    private int id;

    public Student(String name, int id) {
        super(name);
        this.id = id;
    }

    public int getID() {
        return id;
    }

    public void setID(int newID) {
        id = newID;
    }

    public String toString() {
        return id + ", " + name;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:27:51+00:00Added an answer on May 27, 2026 at 4:27 am

    Change your interface from:

    interface Comparable<Element> 
    {     
       public int compareTo(Element nodeA, Element nodeB); 
    }
    

    to:

    interface Comparable<Element> 
    {     
       public int compareTo(Element nodeA); 
    }
    

    And make your Person class be defined as:

    abstract class Person implements Comparable<? extends Person> { /* ... */ }
    

    And make your Student (and other Person-subclasses be):

    class Student extends Person { /* ... */ }
    

    That is all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract Class Monitor.java which is subclassed by a Class EmailMonitor.java .
I have an abstract class defining a pure virtual method in c++: class Base
I have an abstract class, Foo, that has a non-abstract method called Bar. I
I have an abstract class that has a virtual method. The method is virtual
I have an abstract class which I would like to be able to expose
I want to create an abstract class in C#. Currently, I have this class
I have some classes that look like this: MODEL public abstract class BaseEntity<O extends
I have an abstract base class called Person with subclasses Employee and Customer. How
I have abstract class A, from which I inherit a number of classes. In
I have an abstract base class from which many classes are derived. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.