<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// class with static variable
class Stuff {
  static int k;
  Stuff() {}
}

// class for main
public class Static_var {
  public static void main(String args[]) {
    
    // static means don't need to instantiate an object
    Stuff.k = 2;
    System.out.println(Stuff.k);

    // static also means all objects from same class "know"
    // the static variable... setting it one object, sets it for
    // all obects

    Stuff S = new Stuff();
    S.k = 1;
    
    Stuff A = new Stuff();
    Stuff B = new Stuff();
    
    System.out.println(S.k);
    System.out.println(A.k);
    System.out.println(B.k);
    
  }
  
}

</pre></body></html>