Interview Questions

Where are the local variables stored in JVM?

The variables which are declared within a method are called Local variables. Once a local variable is created inside the method, then its memory reference in created in the Java Stack. Once the method completes it execution, the Java stack for this method will be elapsed hence the Local variable will be removed from the Java stack and no longer be reclaimed or used.

If the local variable is an Object, then the actual object creation happens in the Java Heap but the object reference will be placed in the Java Stack.