When a class has static members, all instances of the class will use the same member. The member exists only at one place in memory. With non-static members, each instance has its own copy stored at different memory locations.
When - or if it all - to use static members depends on what you want to do. If you are not sure avoid them. An example for using static members might be a class that uses one time initialisation for values that do not change during runtime like the screen resolution:
class SomeClass {
private static boolean initialised;
private static int width;
private static int height;
public SomeClass() {
if (!initialised)
{
width = getScreenWidth();
height = getScreenHeight();
initialised = true;
}
}
}
When having static member variables you should also make the getter and setter functions static. While not really necessary it allows using them without having a class instance:
Character c1 = new Character();
double points1 = c1.getHitPoints();
double points2 = Character.getHitPoints();
For your case change the
stats
member to a single
int
and create multiple instances of the class:
Character characters = new Character[6];
for (int i = 0; i < characters.length; i++) {
characters[i].getValues();
}
display(characters);
If some members are constant for all instances, you can make those static. But there are none in your example.