0

Hi, I'm trying to write a program right now that requires inheritance. I understand the concept and what I'm supposed to do, but I'm having trouble with the syntax. I created a class called student and created its methods and attributes, and then I created a constructor called student. Next I need to create subclasses called Graduate, Undergraduate, and part-time and create additional methods for them. I keep getting an error saying "Cannot find constructor Student" and I can't figure out why. Here's my code. Line 75 is the issue line. Thanks.

public abstract class Student {

    private String firstName;
    private String lastName;
    private int studentID;
    private double gPA;
    private String status;
    private String mentor;

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public int getStudentID() {
        return studentID;
    }

    public double getGPA() {
        return gPA;
    }

    public String getStatus() {
        return status;
    }

    public String getMentor() {
        return mentor;
    }

    public void setFirstName(String fName){
        firstName = fName;
    }

    public void setLastName(String lName) {
        lastName = lName;
    }

    public void setStudentID(int sID) {
        studentID = sID;
    }

    public void setGPA(double sGPA) {
        gPA = sGPA;
    }

    public void setStatus(String sStatus) {
        status = sStatus;
    }

    public void setMentor(String sMentor) {
        mentor = sMentor;
    }

    public Student(String fName, String lName, int sID, double sGPA, String sStatus, String sMentor) {

        firstName = fName;
        lastName = lName;
        studentID = sID;
        gPA = sGPA;
        status = sStatus;
        mentor = sMentor;

    }

    public abstract void calculateTuition();
    public abstract void update();
    public abstract void add();
    public abstract void delete();
    public abstract void query ();

public class Graduate extends Student {

}
}

Edited by jrookie: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

This is all about the default constructors that Java provides when you don't provide one.
Student has a defined constructor with ~6 params, so that's that. End of story.
Graduate has no constructor defined, so Java provides a default no-args constructor for you.
If a constructor does not begin with a call to a superclass constructor Java provides a default call to the default (no-args) constructor of the superclass as the first line of the constructor. So, because you didn't define a constructor for Graduate, Java provided one that goes

public Graduate() {
   super();
}

BUT - Student doesn't have a no-args constructor, so Java can't find it, so you get the error.
You fix it by writing a constructor for Graduate, with it's first line being a call to the constructor that you already defined for Student.
Wow.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.