[Solved] Local Variable Initialization Java [duplicate]


Look at it like this what happens when the if condition in your code is not met? The reason you would be getting an error saying :

The local variable var may not have been initialized

is because if the condition is false you really don’t have var initialised, do you?

On the other hand else was serving the purpose of ensuring the initialization in the existing code for you.

2

solved Local Variable Initialization Java [duplicate]