title: Java pass by value clarified
body: <p>I have a list of Cell object that represent a board game inside the board class.</p>
  
  <pre><code>Cell boardGame[][] = new Cell[8][8];
  </code></pre>
  
  <p>I needed a temporary cell to try the player move on him and compare it to the other cells, so I though that I could use a java pass-by-value to do it.</p>
  
  <pre><code>test(board.boardGame);
  board.printBoard(); 
  
  private static void test(Cell[][] boardGame) {
  Cell c = new Cell((new Soldier(ChessPiece.QUEEN, Color.WHITE)), 7, 4);
      boardGame[7][7] = c;
  
  }
  </code></pre>
  
  <p>I read some post about java here, but apparently I still didn't catch it 100%.</p>
  
  <p>I expected to see only one white queen on the board, but I saw two.
  I know that if you pass a reference you can change its values, but I though that if I would pass the array itself its members won't be modified unless I would execute a return.</p>
  
  <p>Please help me to understand this subject better.
  Thanks</p>
  
  <p>Edit:</p>
  
  <p>I think I don't understand when it called attributes and where it doesn't.
  I though the different it if you are call "new" or not.</p>
  
  <p>When its part of another object it called attribute right? but every object can be created as part of another object. I can create a new string in dog class and then create the dog class in the animal class and then create it in another class. So only the top class is in the stack?</p>
  
  <p>For exemple:</p>
  
  <pre><code>public class Board  { //fake class
  
      int num= 0;
      public void test(int i){
          i = 1;
      }
  }
  </code></pre>
  
  <p>and on another class:</p>
  
  <pre><code>    public class Main {
          static void outsideTest(Board board){
              board.num = 1;
          }
      public static void main(String[] args) {
          Board board = new Board();
          System.out.println(board.num);
          board.test(board.num);
          System.out.println(board.num);
          outsideTest(board);
          System.out.println(board.num);
  }
  }
  </code></pre>
  
  <p>Now I didn't understand why on test() method the num didn't change and on outsideTest() the num change, num as been created in the heap because its part of the board object, so its need to be changed on both cases no?</p>