java - When making a class to hold variables should the variables always be static? -


say wanted make class hold set of integers accessed multiple other classes , instances. don't want them reverting value had when code compiled. mean have static, in order keep them going original value? example

the original stats holding class here:

public class stats() {      public static int numone = 0;     public static int numtwo = 5;     public static int numthree = 3     //etc...  } 

it called on in 2 places. here:

public class exampleclass() {      private stats stats = new stats();     stats.numone += 5;     //more variable changes.  } 

also here:

public class exampleclasstwo() {      private stats stats = new stats();     stats.numone -= 3;     //more variable changes.  } 

will these calls reset variables original class value if variables not static? if so, mean should static?

no, variables maintain state without static modifier


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -