title: Scope of static variable and methods in Java
body: <p>I have some doubts about usage of static method in Java.
  I read many places static variables are instance independent so be comes global.</p>
  
  <pre><code>public class ThirdClass {
      public static var = "Java";
  }
  
  public class Second {
      public static void main(String[] args) {
          ThirdClass ob1 = new ThirdClass();
          System.out.println(ob1.var);   // prints Java
          ob1.var="Ruby";
          ThirdClass ob2 = new ThirdClass();
          System.out.println(ob2.var);   // prints Ruby
      }
  }
  
  public class First {
      public static void main(String[] args) {
          ThirdClass ob3 = new ThirdClass();
          System.out.println(ob1.var);   // prints Java again!!!
      }
  }
  </code></pre>
  
  <p>As you see in second class multiple instance of ThirdClass  sharing same instance of variable var. But a separate instance in class First don't access the final value "Ruby"  but show original "Java".  It means the static variable are NOT global variable but only global to single execution!!!</p>
  
  <p>Also do is creating static variable resource intensive  compared to instance variable?</p>
  
  <p>Please suggest.</p>