As a rule, a final variable has to be initialized only once. No other initializations are permitted. If it is so then, what happens when a final variable is declared inside a method. Suppose the method which a final variable is declared within is invoked/called thrice, the declaration statement of that final variable within the method is executed thrice and the final variable should be initialized thrice which is illegal specifically in Java by convention. In such a scenario, how could the compiler maintain the final variable inside a method?
Share
The local variable is only in scope for the duration of the method. The variable can be initialized once for each method scope.
You might want to read up on the stack vs the heap to learn about how the JVM holds data for a method.