I am just working on my knowledge of ArrayLists and have a question.
I have 4 classes, a person superclass, employee subclass, pupil subclass and a manager subclass of employee.
What I don’t understand is how I can use the method m.setBonus on the people ArrayList. I know I can split the objects into separate arrays but I’m not sure if that is the answer.
I am currently getting an error on the Manager m : manager part because there is no reference for manager I assume.
I currently have this code in my test class
public static void main(String[] args){
ArrayList<Person> people = new ArrayList<Person>();
people.add(new Employee("Tom", 4000, 1990, 3, 10));
people.add(new Pupil("Dick", "Comp Sci"));
people.add(new Employee("Harry", 4000, 1990, 3, 10));
people.add(new Manager ("Dan", 5000, 1990, 10, 1));
for (Manager m : manager)
{
m.setBonus(5000);
}
for (Person p : people){
System.out.println(p.getDetails());
}
}
}
I am sorry if this is a really simple thing. I just can’t find anything on the net.
Cheers
The manager arrayList does not exist, instead do the check in your existing Person loop.