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

javascript - addthis share facebook and google+ url -

java - Simulate the tossing of a coin three times and print out the percentage of cases in which one gets three tails -

c++ - Class declaration error at explicit keyword -