how to do two constructors with super

Solutions on MaxInterview for how to do two constructors with super by the best coders in the world

showing results for - "how to do two constructors with super"
Kenza
28 Oct 2019
1public Student(double avgGPA, int ID, String[] classes, String name){
2    super(name);
3    setVars(avgGPA, ID, classes);
4}
5
6public Student(double avgGPA, int ID, String[] classes, String name, int age){
7    super(name, age);
8    setVars(avgGPA, ID, classes);
9}
10
11public Student(double avgGPA, int ID, String[] classes, String name, int age, String homeTown){
12    super(name, age, homeTown);
13    setVars(avgGPA, ID, classes);
14}
15
16private void setVars(double avgGPA, int ID, String[] classes) {
17    this.avgGPA = avgGPA;
18    this.ID = ID;
19    this.classes = classes;
20}
Nicola
28 Sep 2020
1public Person(String name){
2    this(name, 18, "Atlanta");
3}
4
5public Person(String name, int age){
6    this(name, age, "Atlanta");
7}
8
9public Person(String name, int age, String homeTown){
10    this.name = name;
11    this.age = age;
12    this.homeTown = homeTown;   
13}