title: Java Variable Scope - Instance and class variables
body: <p>I am new to Java and trying to learn by myself. I wrote the below code and I was wondering why the output is not as I expect. Below is the code I have written:</p>
  
  <pre><code>public class Roughwork {
  
      public static int classVar = 25;
  
      public void getValue(int a){
          classVar = a;
          System.out.println(classVar);
  
      }
  
      public static void main(String[] args) {
          Roughwork test = new Roughwork();
          System.out.println(classVar);
          test.getValue(30);
          System.out.println(classVar);
      }
  
  }
  </code></pre>
  
  <p>and the output of this program is:</p>
  
  <pre><code>25
  30
  30
  </code></pre>
  
  <p>I expected the output to be</p>
  
  <pre><code>25
  30
  25
  </code></pre>
  
  <p>What exactly is happening and What I have to do to get my expected output?</p>