A local variable, i.e., method level variable or a parameter cannot be declared as static or public/private/protected.
So local variables must be declared without these modifiers.
For example, the following code is wrong:
void methodA(static int param) {
System.out.println(param);
}
void methodB(private int param) {
System.out.println(param);
}
void methodC() {
private static int methodVariable = 10;
System.out.println(methodVariable);
}
So local variables must be declared without these modifiers.
For example, the following code is wrong:
void methodA(static int param) {
System.out.println(param);
}
void methodB(private int param) {
System.out.println(param);
}
void methodC() {
private static int methodVariable = 10;
System.out.println(methodVariable);
}
To resolve the error, remove static and the access modifiers from the local variable declarations. Only the class level variables (declared outside of any method) can be declared with static and access modifiers.