我正在尝试编写扩展学生的本科课程
这是基类(学生)
public class Student{
private String name;
private int id;
private double gpa;
public Student(){
}
public Student(int id, String name, double gpa){
this.id = id;
this.name = name;
this.gpa = gpa;
}
public Student(int id, double gpa){
this(id, "", gpa);
}
public String getName(){
return name;
}
public int getId(){
return id;
}
public double getGPA(){
return gpa;
}
public void setName(String newName){
this.name = newName;
}
@Override
public String toString(){
return "Student:\nID: " + id + "\nName: " + name + "\nGPA: " + gpa;
}
}
这里是派生类(本科)
public class Undergrad extends Student {
private String year;
public Undergrad (int id , String name ,double gpa,String year)
{
super(id,name , gpa);
this.year =year;
}
@Override
public String toString(){
return super() + " the year is :" + year;
}
}
我面临的问题是eclipse表明我 在Undergrad类的toString方法中 有一个错误, 恰好在super()调用错误说
“令牌“超级”的语法错误,名称无效”
请问有什么帮助吗?