public class Test {
public static void main(String[] args) {
static final String data = "test"; //Illegal modifier for parameter dataFile; only final is permitted.
}
}
//Illegal modifier for parameter dataFile; only final is permitted.
/*
The modifiers private, protected, and public cannot be used on variables
inside of a method. This is because you can only have local variables
inside of methods.
Java is simply telling you that the only modifier allowed at that time
is the final keyword.
*/
The static variable is only associated with class.It is meaningless in a method.
本文探讨了Java中关于非法修饰符使用的常见错误,并解释了为什么在方法内部不能使用如public、protected或private等修饰符,同时强调了static变量与方法内局部变量的区别。
1万+

被折叠的 条评论
为什么被折叠?



