我们可以将数组声明为局部变量或方法参数,但是数组不能是静态的。
public class Test{
public void sample(){
static int[] myArray = {20, 30};
System.out.println();
}
public static void main(String args[]){
Test t = new Test();
t.sample();
}
}C:\Sample>javac Test.java
Test.java:3: error: illegal start of expression
static int[] myArray = {20, 30};
^
1 error