title: Java Error: illegal start of expression
body: <p>I'm basically refining, completing and trying to compile a test code from a reference book for java beginners. The objective is to create a guessing game wherein the target is located in 3 continuous cells (I'm holding the locations in an array) and the user guesses the cell no. to destroy the target cell by cell.</p>
  
  <p>I checked out half a dozen posts here on the same error, but I couldn't figure out what was going wrong.</p>
  
  <p>This is my error:</p>
  
  <pre><code>test.java:5: error: illegal start of expression
   public int[] locations={1,2,3};
   ^
  1 error
  </code></pre>
  
  <p>and my code is:</p>
  
  <pre><code>public class test{
  
          public static void main(String[] args){
  
              test dot=new test();
              public int[] locations={1,2,3};
  
              dot.setLocationCells(locations);
  
              String userGuess="2";
              String result = dot.checkYourself(userGuess);
              String testResult="failed";
  
              if(result.equals("hit")){
                  testResult="passed";
              }
  
  
            System.out.println(testResult);
          }
  
  public String checkYourself(String stringGuess){
          int guess=Integer.parseInt(stringGuess);
          String result="miss";
          int numOfHits=0;
  
          for(int cell:locations){
              if(guess==cell){
                  result="hit";
                  numOfHits++;
                  break;
                  }
              }
  
          if(numOfHits==locations.length){
              result="kill";
              }
  
         System.out.println(result);
         return result;
      }
  
  
  public void setLocationCells( int[] locations){
          int[] locns;
          locns=locations;
          }
  
  }
  </code></pre>