   [java] Design problem: Inheriting constants, or something
  Hey!The problem: Let's say I have an abstract Monster class for my game. It has an instance variable for currentHp, and a constant for maxHp (or MAX_HP). Then I want to have a heal() method in Monster that sets currentHp = maxHp. Then, I want to have different subclasses, for example Skeleton and Orc, with different values in maxHp, so that the method heal() can be used but then sets the currentHp to the right maxHp.But, to my knowledge, the constant in Monster will be used all the time the heal method is used, even if I redeclare (override) the constant in the subclasses. The superclasses constant will be used becase the method is in that class. And I must have something declared there, or else the heal() method will not find the symbol maxHp.So I want like an abstract variable/constant, but abstract variables are not allowed, as far as I know (I've tried some different approaches). Is there any way to create what I want?   
  For HP values, max or current, you should just declare the variable as part of an object. Set the variable as private and set by calling the base class's constructor, in this case, Monster.For example public abstract class Monster{    private int currentHP;    private int maxHP;    public Monster(int maxHP)    {  this.maxHP = maxHP;  this.currentHP = this.maxHP;    }    public void heal()    { if(this.currentHP + 5 < this.maxHP) {this.currentHP += 5; } else if(this.currentHP < this.maxHP) {    this.currentHP = this.maxHP; }    }    ...}public class Skeleton extends Monster{   public Skeleton(int maxHP)   { super(maxHP);   }   ...};  Thanks, but it would be nicer if I didn't have to specify what is a constant, really, in the constructor... :/Btw, this kind of thing is what I found best so far:public class MajorHeal extends Spell {static final int cooldown = 90;public Heal() {super(cooldown);}}So that I don't have to give it to the MajorHeal spell when I do new MajorHeal();   ;  If you don't want the maxheal to be a datamember, you coulduse a virtual function returning the maxHealth - overide this in the derived classes as needed.;  Ah, I get it... yeah that's kinda good.Like this:abstract public class Monster {    abstract public int getMaxHp();    public void heal() {    currentHp = getMaxHp();    }}public class Skeleton extends Monster {    static final int maxHp = 200;    public int getMaxHp() {   return maxHp;    }};  From what I understand maxHP can change. Then if a value can change it means it is not a constant. About that?public abstract class Monster {protected int maxHP;protected int currentHP;void heal(){currentHP = maxHP;}public static void main(String[] args) {Pirate p = new Pirate();p.heal();System.out.println(p.currentHP);}}public class Pirate extends Monster {public Pirate() {maxHP = 100;}}output is:100And if you have a monster fooling around at 0 HP this means you forgot to set the maxHP!Also I would suggest to look at the Factory Pattern here. That could help you a lot. Or not at all....   