I have an abstract class that several classes inherit from with attributes health and damageTaken, and within it there's a method called takeDamage(). Here's what it does:
public double takeDamage(int damage) {
if(health <= 0) {
return 0;
}
damageTaken += damage;
health -= damage;
return health;
}
Since several classes extend the class, I'm trying to get the class Zombie to be instantiated and call the takeDamage() in a Test class. Here's my code for that:
Zombie rob = new Zombie(100, 12, 3.4, 16, true, 500, "Sample Description");
rob.takeDamage(15);
When I try to call takeDamage(), I get a "cannot resolve symbol" error. I don't want to override takeDamage() in every single class this inherits from, instead I want the superclass' methods to be able to be called when instantiating a subclass. Any way to do that?