subclass 这个词的意思和我想象中不太一样
例子 We want to create a subclass of Person called CollegeKid, which represents someone who is attending college.
写出的代码是这样的
public class CollegeKid extends Person
{
private double gpa;
1 2 3 4 5 6 public CollegeKid (String n, int a, double g) { super(n, a); /* the rest here */ gpa = g; }
public double getGPA ()
{
return gpa;
}
public void setGPA (double g)
{
gpa = g;
}
} // end class