I have a Shop class that has an array list of type Worker, and I have two classes that inherit (extend) from Worker, called Stocker and Cashier.
My Stocker class adds the variable
int stamina;
and my Cashier class adds the variable
int patience;
Within Shop, I have an ArrayList named workers of type Worker, my questions are:
1) Is it wrong to be adding objects of types Stocker and Cashier into workers even though they both extend from the Worker class?
2) How can I access the variables of the subclasses from the ArrayList? I've tried to use:
workers.get(0).getStamina();
(knowing for a fact that I have added a class of type Stocker to my ArrayList at index 0) - however this does not work..
How can I freely access and use these subclasses from an ArrayList of type superclass?