Calling a parent method from a child class, encapsulation issues in Java -


for reason can't figure out how compile. cannot find setvalue function in line: 'skill.get("level").setvalue(newlevel);'

import java.util.hashmap;  public class stat extends gameobject {     int value;      public stat()     {         name = "accuracy";         value = 1;     }      public int getvalue()     {            return value; }      public void setvalue(int newvalue)     {         value = newvalue;     } }   import java.util.hashmap;   public class skill extends stat {     protected hashmap<string, gameobject> skill;      public skill()     {         name = "swords";         description = "learn how master art of swordmanship";         skill.put("level",new stat("level",1));         skill.get("level").setvalue(newlevel);     } } 

skill.get("level") gameobject, not stat.

probably setvalue defined in stat, not gameobject?

if sure (for instance if checked instanceof or put stat objects in skill-hashmap) can cast result of stat object, this:

((stat)skill.get("level")).setvalue(newlevel); 

edit: copy paste problem: need constructor stat(string, int) (thanks subhrajyoti majumder pointing out)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -