What is local variable in java?

Variables which are declared inside method or block is called local variable. JVM allocate the memory for local variable whenever the enclosing block or method is executed. Scope of the local variables is within the block or method where they are declared.
Local variable should be initialized before using them because JVM will not initialized at run time. Local variables memory allocation will be done in the stack memory.
Local variable can be primitive, reference, final and instance but local variable can’t be static.


Post a Comment