The error i\'m getting is in the fillPayroll() method in the while loop where it says payroll.add(employee). The error says I can\'t invoke add() on an array type Person but th
payroll is an array. You are invoking method on an array. This is not possible.
Instead of using an array use an ArrayList
. You'll be much happier.
Arrays cannot be resized once created. All the boilerplate for managing that is done by ArrayList
. Using arrays with subclasses in elements has other issues too (around covariance). Probably the only line you need to change is:
private final List<Person> payroll = new ArrayList<Person>();
List
s have an add()
method. Arrays don't.
If Class B extends A:
A a=new B();
but not:
B b=new A();
Since payroll is an array it would need to be
payroll[index].add(employee);
If for whatever reason you can't use collections. you want to turn:
payroll.add(employee);
in to:
this.add(employee);