7.现在有如下一段代码
public class Test {
public int aMethod() {
static int i=0;
i++;
return i;
}
public static void main(String args[]) {
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
}
将产生哪种结果?
A. Compilation will fail
B. Compilation will succeed and the program will print“0”
C. Compilation will succeed and the program will print“1”
D. Compilation will succeed and the program will print“2”
正确答案是:A
Compilation will fail 编译将失败
报错信息:Illegal modifier for parameter i; only final is permitted
报错信息:参数i的修饰符非法;只允许final
原因:报错,无论是普通局部方法还是静态局部方法,内部的局部变量都不能有修饰符