title: Unable to understand the value change of a variable pizzaNum
body: <p>In this code below I am trying to make 10 pizzaz (as the value of <code>pizzaNum</code> becomes 10) and then serve them form different threads (I just used one thread for question), but just in the start of run method the value of <code>pizzaNum</code> becomes <strong>0</strong>. Why? I am unable to understand this.</p>
  
  <pre><code>public class NewDiningHall {
      static int pizzaNum; 
      static int studentID;
  
      public void makePizza() {
          pizzaNum++; 
      }
  
      static class PizzaServe extends Thread {
          public void run(){
              System.out.println("Before run "+pizzaNum);
              String result; 
              if (pizzaNum &gt; 0) { 
                 result = "Served "; 
                 pizzaNum--; 
              } 
              else
                  result = "Starved "; 
              System.out.println(pizzaNum+" "+result + studentID); 
              studentID++; 
          } 
      }
  
      public static void main(String[] args){ 
          NewDiningHall d = new NewDiningHall(); 
          for (int i = 1; i &lt;= 10; i++) {
              d.makePizza();
          } 
          System.out.println(d.pizzaNum);
          PizzaServe t1 = new PizzaServe();
          t1.start();
      } 
  }  
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>10<br>
    Before run 0<br>
    0 Starved 0</p>
  </blockquote>