title: Calling a private static variable in java from a different class
body: <p>I think this might be a straightforward question but I have a class that has a private static int variable that is being incremented within the class and I want to display this value in a second class. However, it keeps printing out 0 even though it has been incremented.</p>
  
  <p>Same code would be</p>
  
  <pre><code>public class Test{
  
        private static int toIncrement;
  
        public static int returnValue{
            return toIncrement;
        }
  
        public void test{
           for(int i = 0; i &lt; 4; i++){
                 toIncrement++;
           }
        }
   }
  </code></pre>
  
  <p>So the above code runs and then from another class I call Test.returnValue();
  and this returns 0</p>