Java Error – Illegal Modifier for Parameter – Only final Permitted

Your have modified your question to ask:

I want to understand why it is not permitted, though both are static?

Variables inside a method exist only on the stack frame. The JVM creates a new stack frame every time a method is invoked, and it is discarded once the method completes.

The public keyword is used on classes, methods and fields to control access. There is no concept of access that could be applied to a stack (local) variable. It only exists inside the method when it’s called, and can only be accessed from within the method.

The static keyword is used on fields to denote that only one such member exists across all instances of a class, and on methods to create them as members of the class that do not require an instance. There is no concept of a static state for anything on the stack; it is temporary. The stack frame and all the local variables on it cease to exist once you return from a method call.

Basically, neither make any sense when talking about a local variable.

Leave a Comment