title: Java 2d array of objects
body: <p>I have a cell object with function </p>
  
  <pre><code>public class Cell {
      static int X;
      static int Y;
      static int Val = 0;
      static int Player = 0;
  
      public Cell(int a, int b, int p) {
          // TODO Auto-generated constructor stub
          X = a;
          Y = b;
          Val = 0;
          Player = p;
      }
  </code></pre>
  
  <p>With additional function updateX, updateY, updateVal, updatePlayer and respective get functions. It is called by</p>
  
  <pre><code>    Cell[][] grid = new Cell[7][6];
      for(int i = 0; i &lt; 7; i++)
              for(int j = 0; j &lt; 6; j++)
              {
              grid[i][j] = new Cell(i, j, 0);         
              }       
          System.out.println("wasd");
          grid[0][1].updatePlayer(1); 
          grid[0][1].updateVal(1);
  
          System.out.println("grid[0][1].getval = " + grid[0][1].getVal() + " grid[1][1].getval = " + grid[1][1].getVal());
  </code></pre>
  
  <p>But the output is</p>
  
  <pre><code>grid[0][1].getval = 1 grid[1][1].getval = 1
  </code></pre>
  
  <p>and should be </p>
  
  <pre><code>grid[0][1].getval = 1 grid[1][1].getval = 0
  </code></pre>
  
  <p>What is causing this error?</p>