在编译期间无法识别转换类

时间:2017-06-11 19:02:27

标签: java class methods casting

正如你所看到的,我的学生班是人的一个子类。我在person超类中使用了标准的.equals()方法。在我的.equals()中,对于子类Student,我在方法的第三行收到错误,我从"其他"中转换了一个新的Student对象。错误读取"找不到符号"并发生在这一行学生newStudent =学生(其他);                                                           ^ 为什么符号无法识别?

public class Student extends Person {
private double avgGPA;
private int gtID;
private String[] classes;

public Student(String name, int age, String hometown, int gtID, double avgGPA, String[] classes){
    super(name,age,hometown);
    this.avgGPA = avgGPA;
    this.gtID = gtID;
    this.classes = classes;
}
public double getAvgGPA(){
    return avgGPA;
}
public String[] getClasses(){
    return classes;
}
public int getGTID(){
    return gtID;
}
public String toString(){
    return super.toString() + " with gtid " + gtID;
}
public boolean equals(Object other){
    if (super.equals(other)){
        Student newStudent = Student(other);
        if (this.avgGPA != newStudent.avgGPA){
            return false;
        } else if ( this.gtID != newStudent.gtID){
            return false;
        } else if ( this.classes.length != newStudent.classes.length){
            return false;
        } else {
            for (int i = 0; i < this.classes.length; i++) {
                if (this.classes[i] != newStudent.classes[i]){
                    return false;
                }else {
                    return true;
                }
            }   
        }
    }
}   

}

0 个答案:

没有答案