Results 1 to 3 of 3

Thread: Trouble with inheritance

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trouble with inheritance

    Ok i am trying to get these childer classes to go back to the parent but i am having trouble. here is what i need the structure to look like.


    Student ->Highschool, Middleschool, College ( -> undergrad and graduate)


    I am having trouble with taking the info from grad. and undergrad back through to college then to student.
    Here are the errors i am receiving when i try to compile College.java and College.java

    College.java:8: cannot find symbol
    symbol : variable sID
    location: class College
    super(sName, sAge, sID, sSchoolName, sGPA);
    ^
    Graduate.java:8: cannot reference major before supertype constructor has been called
    super(name, age, id, schoolName, gpa, major, minor, time);
    ^
    Graduate.java:8: cannot reference minor before supertype constructor has been called
    super(name, age, id, schoolName, gpa, major, minor, time);
    ^
    Graduate.java:16: cannot find symbol
    symbol : variable temp
    location: class Graduate
    return temp + "\nGraduate degree to be aquired: "+gradDegree+ "\nGRE score: "+GRE;

    here is the code
    Code:
        class College extends Student
       {
          boolean time;
          String major, minor;
       
           public College(String sName, int sAge, int sId, String sSchoolName, double sGPA, String sMajor, String sMinor, boolean sTime)
          {
             super(sName, sAge, sID, sSchoolName, sGPA);
             time = sTime;
             major = sMajor;
             minor = sMinor;
          }
       
           public String toString()
          {
             String temp = super.toString();
             return temp + "\nMajor: "+major+"\nMinor: "+minor+"\n"+time;
          }
       }
    Code:
    class Graduate extends College
    {
    	String gradDegree;
    	int GRE;
    	
    	public Graduate(String name, int age, String schoolName, int id, double gpa, String maj, String min, boolean time, int gre, String degree)
    	{
    		super(name, age, id, schoolName, gpa, major, minor, time);
    		gradDegree = degree;
    		GRE = gre;
    	}
    	
    	public String toString()
    	{
    		String temp1 = super.toString();
    		return temp + "\nGraduate degree to be aquired: "+gradDegree+ "\nGRE score: "+GRE;
    	}
    }
    Last edited by craigtb; 04-05-2007 at 01:54 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    College.java:8: cannot find symbol
    symbol : variable sID
    Case-sensitivity has bitten you again: you defined it as sId.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ahhh yeah thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •