子类的构造函数表示super()未定义

时间:2018-03-15 21:40:52

标签: java constructor

我在java中创建了这个类

  package mainpackage;

  public class Users {
    public char username;
    public char name;
    public char surname;
    public char department;
    public int usersCounter;

    public char getUsername() {
        return this.username;
    }

    public void setUsername(char username) {
        this.username = username;
    }

    public char getSurname() {
        return this.surname;
    }

    public void setSurname(char surname) {
        this.surname = surname;
    }

    public char getName() {
        return this.name;
    }

    public void setName(char name) {
        this.name = name;
    }

    public char getDepartment() {
        return this.department;
    }

    public void setDepartment(char department) {
        this.department = department;
    }

    public int getUsersCounter() {
        return this.usersCounter;
    }

    public void setUsersCounter(int usersCounter) {
        this.usersCounter = usersCounter;
    }

    public Users(char userName, char Name, char surName, char Department, int UsersCounter) {
        username = userName;
        name = Name;
        surname= surName;
        department = Department;
        usersCounter = UsersCounter;
    }   

  }

我还创建了一个子类,我尝试创建子类的构造函数,但它向我显示了一个错误(我把它放在子类的构造函数中),说构造函数Users是未定义的。我是使用Eclipse并且这个问题的唯一解决方案是创建构造函数Users,但它已经存在!!!

  package mainpackage;

  public class Students extends Users {

    static int registrationNumber;

    @SuppressWarnings("static-access")
    public int getNumber() {
        return this.registrationNumber;
    }

    @SuppressWarnings("static-access")
    public void setNumber(char registrationNumber) {
        this.registrationNumber = registrationNumber;
    }

    public Students(char userName, char Name, char surName, char Department, int UsersCounter,int RegistrationNumber) {
        super(userName, Name, surName, Department, UsersCounter);
        registrationNumber = RegistrationNumber;
    }

    }

0 个答案:

没有答案