PreQuiz 2 - Spring 2006
Here's the Student.java class that we created in class.
public class Student extends Person {
  
  private String school;
  private int schoolID;
  
  public Student(String someName){
    super(someName); // Must be the first line
    this.defaultSchool();
  }
  
  public Student(String someName, int someID){
    super(someName,someID);
    this.defaultSchool();
  }
  
  public String getSchool(){
    return this.school;
  }
  
  public void setSchool(String someSchool,int someID){
    this.school = someSchool;
    this.schoolID = someID;
  }
  
  public void defaultSchool(){
    this.school = "Gwinnett College";
  }
  
  public String toString(){
    return super.toString()+". And I'm a student at "
      +this.getSchool()+" and my school ID is "+this.schoolID;
    /*return "I'm a student at "
      +this.getSchool()+" and my school ID is "+this.schoolID;*/
  }
  
  public void greet(){
    super.greet();
    System.out.println("Go away -- I'm late for class! I'm a student at "
                         +this.getSchool());
  }
  
  public void countDownFrom(int endNumber){
    System.out.println("Counting..."+endNumber);
    if (endNumber == 1)
    {return;}
    countDownFrom(endNumber-1);
  }
}
Write a new constructor so that we can create students with a Name, ID, School, and School ID.
Comments, questions, and answers!
public Student(String someName, int someID, String school, int schoolID){
    super(someName,someID);
    this.setSchool(school, schoolID);
  }
So, we don't have to declare the 2 new variables, since they are already declared before the constructors, 
and the superclass (Person) already sets name and id, so all we have to do is add the 2 input parameters and 
call setSchool().
My question is this:
  Traditionally, variables are local to functions...  Does this hold true to the constructor?–
In other words, can I name 2 of my inputs String school and int schoolID in a constructor?  It seems reasonable...
But I want to be sure they don't refer to the 2 defined in the class...
Links to this Page