📜  如何用 super 做两个构造函数 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:09.809000             🧑  作者: Mango

代码示例2
public Student(double avgGPA, int ID, String[] classes, String name){
    super(name);
    setVars(avgGPA, ID, classes);
}

public Student(double avgGPA, int ID, String[] classes, String name, int age){
    super(name, age);
    setVars(avgGPA, ID, classes);
}

public Student(double avgGPA, int ID, String[] classes, String name, int age, String homeTown){
    super(name, age, homeTown);
    setVars(avgGPA, ID, classes);
}

private void setVars(double avgGPA, int ID, String[] classes) {
    this.avgGPA = avgGPA;
    this.ID = ID;
    this.classes = classes;
}