Accessing non-static fields from another class, before object creation
Hiya guys. I am confusing myself with this problem so please bear with me in trying to explain it.
I am making a Payroll program that will store payroll information. Currently I have a Payroll class which is static and has one field, an ArrayList of Persons, and methods to add/remove Persons and print its contents. I am adding entries to the Payroll's ArrayList, but I would like to be able to do this in a non-static context so I could have multiple, seperate Payrolls.
My problem is that in the Person class I have a static method that reads information from a file and adds it to the ArrayList as a Person (and loops for as many Person's details are present). However, I don't know how I would go about accessing the Payroll's ArrayList from the Person class before the Payroll object has been created, if I want to make it non-static.
Naturally, it would be easier to place this method in the Payroll class, however this is coursework and part of the specification was that it would be inside the Person class. My feeling is it's simply not possible and the professor intended Payroll to be static, but I would appreciate any information I could get.
My code is something like this:
public class Payroll
public ArrayList<Person> payrollArray = new ArrayList<Person>();
public static class Person
public Person(String inName)
name = inName;
public static void addPersonsFromFile()
//...read data from file to newPerson