title: what does the static modifier do in java
body: <p>In this book, there is this example of how to use static variables and methods. I dont understand what is going on. explain why there has to be static in front of the methods and variables. There are two seperate classes called Virus and VirusLab. The VirusLab.java takes in a command line argument and makes the amount of Virus objects, then spits out the number of Virus objects. Thanks</p>
  
  <p>Virus:</p>
  
  <pre><code>public class Virus {
  
  static int virusCount = 0;
  
  public Virus() {
      virusCount++;
  }
  
  public static int getVirusCount() {
      return virusCount;
  }
  
  }
  </code></pre>
  
  <p>VirusLab:</p>
  
  <pre><code>public class VirusLab {
  public static void main(String[] args) {
      int numViruses = Integer.parseInt(args[0]);
      if (numViruses &gt; 0) {
          Virus[] virii = new Virus[numViruses];
          for (int i = 0; i &lt; numViruses; i++) {
              virii[i] = new Virus();
          }
          System.out.println("There are " + Virus.getVirusCount()
                  + " viruses.");
      }
  }
  }
  </code></pre>