ArrayList<Person> people = new ArrayList();
people.add(new Person ("Andrew", "Shearer", "AS10101"));
people.add(new Person("Gordon", "Eccleston", "GE10101"));
people.add(new Person("Ben", "Allen", "BA10101"));
people.add(new Person("Ryan", "May", "RM10101"));
for (int i = 0; i < people.size(); i++) {
System.out.println(Person.toString());
}
When running I get an error concerning the toString method saying I can't use a non-static method in a static context. To me it looks like this is because I haven't actually created instances of the object and I'm trying to envoke the toString method on the Person class rather than the objects. However, I can't seem to find how to fix this. Have I done something wrong in the .add lines or is it in the for loop?


Sign In
Create Account


Back to top









