Calling a private static variable in java from a different class -


i think might straightforward question have class has private static int variable being incremented within class , want display value in second class. however, keeps printing out 0 though has been incremented.

same code be

public class test{        private static int toincrement;        public static int returnvalue{           return toincrement;       }        public void test{          for(int = 0; < 4; i++){                toincrement++;          }       }  } 

so above code runs , class call test.returnvalue(); , returns 0

so above code runs , class call test.returnvalue(); , returns 0

when above code runs, not mean test method execute automatically, without being called anywhere. if call test method first , try test.returnvalue() value should not 0.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -