title: Java Creating a Copy of a class
body: <p>I want to copy an object, I tried clonable but failed.
  To Implement minimax function I need to create a copy of the board class and check the best move</p>
  <p>in my AIPlayer class</p>
  <pre><code>private int pickBestMove(Piece piece){
          int bestScore = 0;
          int bestCol = r.nextInt(board.NUM_OF_COLS);
          int[] validLocations = getValidLocations();
          for (int c = 0; c &lt; validLocations.length; c++) {
               int row = board.findNextAvailableSpot(c);
  
               Board tempBoard = new BoardImpl(board.getBoardUI()); //Need to copy the board object here
  
               tempBoard.updateMove(c, row, piece);
               int score = scorePosition(tempBoard, piece);
               if(score &gt; bestScore){
                   bestScore = score;
                   bestCol = c;
               }
          }
          System.out.println(&quot;Best Move is &quot; + bestCol);
          return bestCol;
      }
  </code></pre>
  <p>Board is a interface, and BoardImplement is it's subclass</p>
  <pre><code>public interface Board {}
  </code></pre>
  <p>I tried the clonnable</p>
  <pre><code>public class BoardImpl implements Board, Cloneable {
  //My other stuff
  public BoardImpl clone() {
          try {
              BoardImpl clone = (BoardImpl) super.clone();
              // TODO: copy mutable state here, so the clone can't change the internals of the original
              return clone;
          } catch (CloneNotSupportedException e) {
              throw new AssertionError();
          }
      }
  }
  </code></pre>
  <p>I tried adding this code to AIPlayer class (Mentioned above)</p>
  <pre><code>     Board tempBoard = (Board) board.clone();
  </code></pre>
  <p>but it failed,</p>
  <blockquote>
  <p>'clone()' has protected access in 'java.lang.Object</p>
  </blockquote>
  <p>What are the solution that I can do for this?</p>
  <p>Thanks for your time.</p>