I know that method variables are stored on stack of the memory but slightly confused over final
. I had browsed many links like this could not get proper understanding? below is the example of inner class
in which final
variables are accessed and local non-final
variables are not as they are stored in stack
class Employee {
public void getAddress(){
final int location = 13;
int notFinalVar = 13;
class Address {
System.out.println (location);
System.out.println (notFinalVar); // compiler error
}
}
Update: Just now came to know about hidden fields called synthetic field
( inner class heap memory area
) in which copy of final variables are stored so does it finally means that final variables are stored in finally Stack memory Area
?