找不到超级陈述的象征

时间:2013-09-01 13:42:30

标签: java inheritance polymorphism symbols super

这是一个带有继承和多态方法的java代码。

学生班

public abstract class Student
{
    protected long id;
    protected String name;
    protected String programCode;
    protected int part;

    public Student(){
        id=0;
        name=" ";
        programCode=" ";
        part=0;
    }

    public void setStudent(long i,String nm,String code,int pt){
        id=i;
        name=nm;
        programCode=code;
        part=pt;
    }

    public long getId()            {return id;}    
    public String getName()        {return name;}    
    public String getProgramCode() {return programCode;}    
    public int getPart()           {return part;}    
    public abstract double calculateFees();

    public String toString(){
       return ("ID: "+id+"\nName: "+name+"\nProgram Code: "+programCode+"\nPart: "+part);}
    }

FullTimeStudent Class

public class FullTimeStudent extends Student{
    protected String collegeName;
    protected String roomNumber;

public FullTimeStudent(){
    super();
    collegeName=" ";
    roomNumber=" ";
}    
public FullTimeStudent(long i,String nm,String code,int pt,
                              String collegeNm,String roomNum){
    super(i,nm,code,pt); //can't find symbol here
    collegeName=collegeNm;
    roomNumber=roomNum;
}    
public void setFullTimeStudent(String collegeNm,String roomNum){
    collegeName=collegeNm;
    roomNumber=roomNum;
}    
public String getCollegeName()   {return collegeName;}
public String getRoomNumber()    {return roomNumber;}

public double calculateFees(){
    double fee=0, collegefee=0, totalfee=0;

    if(programCode.equals("BIT")){
       fee=2000;
    }
    else if(programCode.equals("BCHE")){
       fee=2300;
    }
    else if(programCode.equals("BPHY")){
       fee=3200;
    } 
    else if(programCode.equals("BBIO"))
       fee=2700;
    } 

    if(collegeName.equals("Jati")){
       collegefee=200;
    }
    else if(collegeName.equals("Cengal")){
       collegefee=350;
    }
    else if(collegeName.equals("Dahlis")){
       collegefee=420;

       totalfee=fee+collegefee;
       return totalfee;
    }

public String toString(){
     return super.toString()+"\nCollege Name: "+collegeName+"\nRoom Number"+roomNumber;
}

}

似乎无法在FullTimeStudent中找到超级语句的符号 类。

super(i,nm,code,pt); 

2 个答案:

答案 0 :(得分:1)

正如错误试图告诉你的那样,你的超类没有任何带参数的构造函数。

答案 1 :(得分:1)

Student#setStudent的方法声明更改为FullTimeStudent

构造函数中预期的重载构造函数的声明
protected Student(long i, String nm, String code, int pt) {
    id = i;
    name = nm;
    programCode = code;
    part = pt;
}

然后可以将no-args构造函数简化为

protected Student() {
   this(0, " ", " ", 0);
}

(将文字值的转换保留为预定义的常量作为练习)