title: Static variables in java
body: <p>I have scenario like this</p>
  
  <pre><code>public class Test{
  
     static int a;
     int b;
  
     public static void main(String[] args){
  
        Test t1  = new Test();
        Test t2 = new Test();
  
     }
  }
  </code></pre>
  
  <p>What will be the variables in object t1 and object t2?</p>
  
  <p>As per my understanding since variable <code>a</code> is a static variable it will be both in object 1 and object 2.</p>
  
  <p>And <code>b</code> will be created separate copy for both the objects.</p>
  
  <p>But when I assign a value to variable b ie(<code>int b=1</code>) and call it like <code>System.out.println(t1.b)</code>, <code>System.out.println(t2.b)</code> </p>
  
  <p>Instead of getting an error I am getting 1 as output from both the objects.</p>
  
  <p>Why is that?</p>