public class Student {
private String name;
private String id;
private String email;
private ArrayList<Student> s;
public Student( String n, String i, String e)
{
n = name; i= id; e = email;
}
}
public class Library {
private ArrayList<Student> s;
public void addStudent(Student a)
{
s.add(a);
}
public static void main(String[] args)
{
Student g = new Student("John Elway", "je223", "j@gmail.com");
Student f = new Student("Emily Harris", "emmy65", "e@yahoo.com");
Student t = new Student("Sam Knight", "joookok", "fgdfgd@yahoo.com");
s.addStudent(g);
s.addStudent(f);
s.addStudent(t);
}
}
似乎我的学生对象将被添加到学生的数组列表中,但它不是那样工作的。由于 arraylist 在库类而不是 Student 类中,它是否不起作用?