Results 1 to 3 of 3

Thread: Inheritance

  1. #1
    NewToJava_99 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Inheritance

    I am working on an assignment and cannot figure out why i am getting errors when trying to inheret from a superclass. I have the following structure

    Person - which is the super class
    ClassPerson - which inherits from the Person class
    Instructor - which inherits from the ClassPerson class

    I can compile the Person and ClassPerson classes, however when i attempt to compile the instructor class i get the following error:

    "Cannot find symbol - constructor ClassPerson (java.lang.String, java.lang.String)"

    My code is as follows:

    public class Person
    {

    private String firstName;
    private String lastName;
    private double heightInCentimeters;
    private int weightInKg;


    /**
    * Constructor for objects of class Person
    */
    public Person(String firstName, String lastName, double heightInCentimeters, int weightInKg)
    {

    this.firstName = firstName;
    this.lastName = lastName;
    this.heightInCentimeters = heightInCentimeters;
    this.weightInKg = weightInKg;
    }


    ------------------------------------------------------------------------------------------------------------------------------------------------
    public class ClassPerson extends Person
    {

    private String studentNumber;
    private String emailAddress;

    /**
    * Constructor for objects of class ClassPerson
    */
    public ClassPerson(String firstName, String lastName, double heightInCentimeters, int weightInKg,
    String studentNumber, String emailAddress)
    {
    super (firstName,lastName,heightInCentimeters,weightInKg );
    this.studentNumber = studentNumber;
    this.emailAddress = emailAddress;
    }
    --------------------------------------------------------------------------------------------------------------------------------------
    public class Instructor extends ClassPerson
    {
    private int hourlyWage;


    /**
    * Constructor for objects of class Instructor
    */
    public Instructor(String studentNumber, String emailAddress, int hourlyWage)

    {

    super(studentNumber,emailAddress);
    this.hourlyWage = hourlyWage;
    }
    ----------------------------------------------------------------------------------------------------------------------------------------------

    Does anyone know what could be causing this.

    Thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,327
    Rep Power
    25

    Default Re: Inheritance

    "Cannot find symbol - constructor ClassPerson (java.lang.String, java.lang.String)"
    Where is the constructor defined that takes two Strings for that class?

    Please post the full text of the error message that shows where the error occurs.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,199
    Rep Power
    19

Similar Threads

  1. Help with inheritance
    By waker3210 in forum Java Gaming
    Replies: 6
    Last Post: 05-19-2012, 08:27 PM
  2. using inheritance
    By droidus in forum New To Java
    Replies: 1
    Last Post: 10-18-2011, 02:38 AM
  3. JPA Inheritance
    By videanuadrian in forum New To Java
    Replies: 1
    Last Post: 01-10-2011, 06:44 AM
  4. inheritance
    By itaipee in forum New To Java
    Replies: 6
    Last Post: 01-20-2009, 08:18 PM
  5. Inheritance in GUI
    By Marty in forum SWT / JFace
    Replies: 2
    Last Post: 05-11-2007, 12:54 AM

Posting Permissions

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