Top
Previous Next
Java Arrays, Objects, Methods CS 161 - Java

Inheritance Example

Source: examples/CSGradStudent.java



/** encapsulate the characteristics of a Grad student
** @author: Jonathan Doughty
**/
 
public class CSGradStudent extends CSStudent {
 
private static final int MAX = 100;
private CSStudent [] taFor;
private int nextStudent = 0;
 
// A constructor that will create student objects with specified name and id
public CSGradStudent( String studentName, String id) {
super(studentName, id);
taFor = new CSStudent[MAX];
}
 
// Other methods here unique to CSGradStudents
 
public void writeThesis() {
// mumble
}
 
public String toString() {
StringBuffer result = new StringBuffer("CSGradStudent ");
result.append( super.toString() );
if (nextStudent > 0) {
result.append("TA for:\n");
for (int i = 0; i < nextStudent; i++) {
result.append( taFor[i].getName());
result.append("\n");
}
}
return result.toString();
}
}


Top
Previous Next
jwd