这是我的学生班。
public class Student {
private String name;
private long id;
private double gpa;
private PersonalData pd;
public Student(String name, long id, double gpa, PersonalData pd){
this.name= name;
this.id=id;
this.gpa= gpa;
this.pd= pd;
}
public String getName(){
return name;
}
public long getID(){
return id;
}
public double getGPA(){
return gpa;
}
public PersonalData getPersonalData(){
return pd;
}
public String toString(){
String result= "Name: "+ name+ ", ID: "+ id+ ", GPA: "+gpa+", Personal Data: "+ pd;
return result;
}
}
这是测试类:
public class Test {
public static void main(String[] args) {
// TODO, add your application code
PersonalData a= new PersonalData(80,4,1,1232154687);
Student b= new Student(Ali,123,20,a);
}
}
它给出了这个错误:
cannot find symbol
Student b= new Student(Ali,123,20,a);
^
symbol: variable Ali
location: class Test
1 error
我不知道出了什么问题。有人能看到吗?
答案 0 :(得分:0)
如下所示
student b= new Student("Ali",123,20,a);
您的Student
班级constructor
需要String
作为名称,您必须像“”中那样传递它,或者像String Ali=""
那样创建一个字符串变量,然后将阿里传递为
student b= new Student(Ali,123,20,a);