Home > Back-end >  Sun classes inherit the problem
Sun classes inherit the problem

Time:01-16

Public class Main {
Public static void main (String [] args) {
Person p=new Person (" Ming ", 12);
Student s=new Student (" little red ", 20, 99);
//TODO: define PrimaryStudent, inherited from the Student, and the new grade field:
Student ps=new PrimaryStudent (" small army ", 9, 100, 5);
System. The out. Println (ps. GetScore ());
}
}

The class Person {
protected String name;
Protected int the age;

Public Person (String name, int age) {
this.name=name;
this.age=age;
}

Public String getName () {return name; }
Public void elegantly-named setName (String name) {enclosing name=name; }

Public int getAge () {return the age; }
Public void setAge (int age) {this. Age=age; }
}

The class Student extends the Person {
Protected int score;

Public Student (String name, int the age, int score) {
Super (name, age);
This. Score=score;
}

Public int getScore () {return score; }
}

The class PrimaryStudent extends Student {
Protected int grade;
Public PrimaryStudent (String name, int the age, int score, int grade) {
Super (name, age, score);
This. Grade=grade;
}
Public int getGrade () {return grade; }
}

After the operation the Main error. The Java: 40: error: call to super must be the first statement in the constructor
Super (name, age, score);
How is this to return a responsibility excuse me?
  • Related