Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Cannot Find Constructor

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Cannot Find Constructor

    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 {
     
    }
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Cannot Find Constructor

    First off all, you don't have

    public Student()
    {

    }

    Also, I might add, that abstract classes cannot be initialized, at least not to themselves.

    You cannot have

    Student stu = new Student();

    if you had a subclass of Student called MathStudent, you could

    Student stu = new MathStudent();

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Cannot Find Constructor

    I fear you may need a default constructor

    public Student()
    {

    }

    too if you're extending Student.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Cannot Find Constructor

    public abstract class Student {
     
        private String firstName;
        private String lastName;
        private int studentID;
        private double gPA;
        private String status;
        private String mentor;
    // default constructor needed for inheritance
    public Student()
    {
     
    }
        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 {
     
    // if graduate has similar characteristics of Student, then you should
     
    public Graduate (String fName, String lName, int sID, double sGPA, String sStatus, String sMentor, otherVariables)
    {
    super (fName, IName, sID, sGPA, sStatus, sMentor); // calls constructor of superclass
    otherVariables = this.otherVariables;
     
    }
     public  void calculateTuition()
    {
     
    }
        public  void update()
    {
     
    }
        public  void add()
    {
     
    }
        public  void delete()
    {
     
    }
        public  void query ()
    {
     
    }
     
    // other methods, and also a default constructor if you're planning on extending Graduate
    // also, you don't need to have any methods defined here that were already written in Student, unless you're changing
    // what they do or their parameters.  
    // Every method that was abstract in Student MUST be defined, or at least written like I did, in Graduate, otherwise,
    // Graduate will have to be an abstract class too.
    }

  5. The Following User Says Thank You to javapenguin For This Useful Post:

    jrookie (December 8th, 2010)

  6. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Cannot Find Constructor

    Ok, now it makes sense to me. Thank you very much!

Similar Threads

  1. Point constructor
    By upad in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 5th, 2010, 08:34 PM
  2. how to initialise set in a constructor
    By davie in forum Collections and Generics
    Replies: 3
    Last Post: March 12th, 2010, 05:35 PM
  3. calling a constructor
    By turnwellm in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2010, 08:46 PM
  4. Private Constructor
    By Ganezan in forum Object Oriented Programming
    Replies: 4
    Last Post: November 7th, 2009, 04:02 PM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM