I'm having a problem with my constructor in my CollegeStudent Class
http://pics.bbzzdd.com/users/Xylitol/Inhertiance.JPG
return super.toString () + ", student id: " + myIdNum + ", gpa: " +"
Error - myIdNum has private access in Student
Code
Person
class Person
{
private String myName ; // name of the person
private int myAge; // person's age
private String myGender; // "M" for male, "F" for female
// constructor
public Person(String name, int age, String gender)
{
myName = name;
myAge = age;
myGender = gender;
}
public String getName()
{
return myName;
}
public int getAge()
{
return myAge;
}
public String getGender()
{
return myGender;
}
public void setName(String name)
{
myName = name;
}
public void setAge(int age)
{
myAge = age;
}
public void setGender(String gender)
{
myGender = gender;
}
public String toString()
{
return myName + ", age: " + myAge + ", gender: " +
myGender;
}
}
Student
/**
* Write a description of class Student here.
*
* @author (your name)
* @version (a version number or a date)
*/
class Student extends Person
{
private String myIdNum; // Student Id Number
private double myGPA; // grade point average
// constructor
public Student(String name, int age, String gender,
String idNum, double gpa)
{
// use the super class' constructor
super(name, age, gender);
// initialize what's new to Student
myIdNum = idNum;
myGPA = gpa;
}
public String getIdNum()
{
return myIdNum;
}
public double getGPA()
{
return myGPA;
}
public void setIdNum(String idNum)
{
myIdNum = idNum;
}
public void setGPA(double gpa)
{
myGPA = gpa;
}
// overrides the toString method in the parent class
public String toString()
{
return super.toString() + ", student id: " + myIdNum + ", gpa: " + myGPA;
}
}
CollegeStudent
/**
* Write a description of class CollegeStudent here.
*
* @author (your name)
* @version (a version number or a date)
*/
class CollegeStudent extends Student
{
private String zMajor;
private int zYear;
public CollegeStudent (String name, int age, String gender,
String major, int year, double gpa, String idNum)
{
super (name, age, gender, gpa, idNum);
zMajor = major;
zYear = year;
}
public int getYear ()
{
return zYear;
}
public String getMajor ()
{
return zMajor;
}
public int setYear (int year)
{
zYear = year;
}
public String setMajor (String major)
{
zMajor = major;
}
public String toString ()
{
return super.toString () + ", student id: " + myIdNum + ", gpa: " +
myGPA + ", year: " + zYear + ", major: " + zMajor;
}
}
http://pics.bbzzdd.com/users/Xylitol/Inhertiance.JPG
return super.toString () + ", student id: " + myIdNum + ", gpa: " +"
Error - myIdNum has private access in Student
Code
Person
class Person
{
private String myName ; // name of the person
private int myAge; // person's age
private String myGender; // "M" for male, "F" for female
// constructor
public Person(String name, int age, String gender)
{
myName = name;
myAge = age;
myGender = gender;
}
public String getName()
{
return myName;
}
public int getAge()
{
return myAge;
}
public String getGender()
{
return myGender;
}
public void setName(String name)
{
myName = name;
}
public void setAge(int age)
{
myAge = age;
}
public void setGender(String gender)
{
myGender = gender;
}
public String toString()
{
return myName + ", age: " + myAge + ", gender: " +
myGender;
}
}
Student
/**
* Write a description of class Student here.
*
* @author (your name)
* @version (a version number or a date)
*/
class Student extends Person
{
private String myIdNum; // Student Id Number
private double myGPA; // grade point average
// constructor
public Student(String name, int age, String gender,
String idNum, double gpa)
{
// use the super class' constructor
super(name, age, gender);
// initialize what's new to Student
myIdNum = idNum;
myGPA = gpa;
}
public String getIdNum()
{
return myIdNum;
}
public double getGPA()
{
return myGPA;
}
public void setIdNum(String idNum)
{
myIdNum = idNum;
}
public void setGPA(double gpa)
{
myGPA = gpa;
}
// overrides the toString method in the parent class
public String toString()
{
return super.toString() + ", student id: " + myIdNum + ", gpa: " + myGPA;
}
}
CollegeStudent
/**
* Write a description of class CollegeStudent here.
*
* @author (your name)
* @version (a version number or a date)
*/
class CollegeStudent extends Student
{
private String zMajor;
private int zYear;
public CollegeStudent (String name, int age, String gender,
String major, int year, double gpa, String idNum)
{
super (name, age, gender, gpa, idNum);
zMajor = major;
zYear = year;
}
public int getYear ()
{
return zYear;
}
public String getMajor ()
{
return zMajor;
}
public int setYear (int year)
{
zYear = year;
}
public String setMajor (String major)
{
zMajor = major;
}
public String toString ()
{
return super.toString () + ", student id: " + myIdNum + ", gpa: " +
myGPA + ", year: " + zYear + ", major: " + zMajor;
}
}