在我的程序中,有三个班级 Student、School 和 TestStudent。我已经在学生班级中声明了学生状态,并且还有一些获取学生主题的方法,我在学校班级中创建了一个学生类型的数组列表,但是当我尝试在学校访问学生的方法时,我得到错误 newStudent type can not be resolve .这是我的代码。
public class Student {
String name;
String subject;
int age;
Student(String name,String subject,int age){
this.name = name;
this.subject = subject;
this.age = age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public String getSubject(){
return this.subject;
}
public int getAge(){
return this.age;
}
}
public class School {
public ArrayList <Student> students = new ArrayList <Student>();
public void addStudent(String name,String subject,int age){
Student newStudent = new Student(name,subject,age);
students.add(newStudent);
}
public void showSubject(String student){
newStudent.getSubject();
}
}