I have an abstract class with abstract method "Action"
public abstract class BaseAnt {
public BaseAnt(String name, int food, int water) {
/.../
}
public abstract void action ();
}
The class worker extends it:
public class WorkerAnt extends BaseAnt {
public WorkerAnt() {
/.../
}
public void action() {
AppStat.FOOD += mAge*0.1 + 10;
}
}
And I'm trying to make loop
public ArrayList<BaseAnt> antsArray;
for (int i = 0; i < AppStat.antList.size(); i++) {
if (AppStat.antList.get(i).getName() == "Worker") {
AppStat.antList.get(i).action();
}
}
But I can't call the method action! How to fix it?
Error:
The method action() is undefined for the type BaseAnt