Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

java derived program


  • Please log in to reply

#1
Luke1988

Luke1988

    Member

  • Member
  • PipPip
  • 37 posts
hey. i am trying to derive a student class from my a person class. i cant seem to get past 2 compile errors. these are:

personStudent.java:6: cannot find symbol
symbol : constructor Person(java.lang.String,int)
location: class Person
super(theName, theAge);
^



personStudent.java:6: cannot find symbol
symbol : constructor Person(java.lang.String,int)
location: class Person
super(theName, theAge);
^



the code i have written for the two programs is below...any help would be much appreciated.

thanks **Luke**

PERSON CLASS

[codebox]
public class Person
{
protected String name;
protected int age;

public void setName (String theName)
{
name = theName;
}

public void setAge (int theAge)
{
age = theAge;
}

public String getName ()
{
return name;
}

public int getAge ()
{
return age;
}

public void displayDetails ()
{
System.out.println("Name is : " + name );
System.out.println("Age is : " + age );
}
}
[/codebox]


STUDENT_PERSON CLASS

[codebox]
public class personStudent extends Person
{
private int studentNo ;
public personStudent (String theName, int theAge, int num)
{
super(theName, theAge);
studentNo = num;
}
public int getStudentNo()
{
return studentNo;
}

public int setStudentNo()
{
studentNo = num;
}

public void displayDetails ()
{
super.displayDetails();
System.out.println("Student Number Is: " + studentNo);
}
}
[/codebox]


TEST CLASS

[codebox]
public class TestPerson
{
public static void main(String []args)
{
System.out.println("Testing Person class");
System.out.println("---------------------------------------");

// instantiating the class
// constructing an object of type Person
Person Ryan = new Person();


Person Luke = new Person();
Luke.setName("Luke");
Luke.setAge(19);
Luke.setStudentNo(776);

// using the set methods
Ryan.setName ("Ryan") ;
Ryan.setAge (53) ;

Ryan.displayDetails () ;
System.out.println();
Luke.displayDetails();

}
}
[/codebox]
  • 0

Advertisements


#2
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
Hi Luke,

Do you still need help?

Please let us know what progress you have made.

bdlt
  • 0

#3
jpshortstuff

jpshortstuff

    Member

  • Member
  • PipPipPip
  • 119 posts
As far as i can see, the problem is here:

super(theName, theAge);
You are calling this from the personStudent class, which extends Person.
Calling super would call the constructor for Person, passing those parameters in.
The problem is, you haven't set a constructor for Person with those parameters.

So, if you added this constructor to your Person class:
public Person(String theName, theAge)
{
	name = theName;
	age = theAge;
}
Then calling ther super constructor like you did should work.

Or, instead of calling your super constructor, you called use you setter methods of the person class:
public personStudent (String theName, int theAge, int num)
{
setName(theName);
setAge(theAge);

studentNo = num;
}
By using this as your constructor in the PersonStudent class.

Hope that solves your problem, any questions just ask

jpshortstuff
  • 0

#4
Luke1988

Luke1988

    Member

  • Topic Starter
  • Member
  • PipPip
  • 37 posts
thanks for your help jpshortstuff :whistling:
  • 0

#5
jpshortstuff

jpshortstuff

    Member

  • Member
  • PipPipPip
  • 119 posts
not a problem, glad i could be of assistance :whistling:

hope its all running smoothly now
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP