Trying to understand how to correctly access and pass other objects within a program using java.
In my little program we see the following:
I have a combat class that will need to know the current HP of my hero, which is an instance of my Hero class.
Previously, if another class needed to know the hero's HP, I would simply use a static variable to store HP. I was told this was incorrect usage of static. Below, I created a method in combat for the explicit use of passing the hero into combat. Thus, going forward, any time I need combat to access anything related to my hero object, I can.
Does this make sense? Am I on the right path?
public class Combat
{
public void passHero(Hero hero1)
{
}
}
public class Main
{
public static void main(String args[])
{
Hero hero1 = new Hero();
//passing hero to Combat
combat.passHero(hero1);
}
}