i have a Problem with understanding the function of the stack Memory in Java. According to my teacher, the following method would create 2 primitive type local variables in the stack Memory.
private void test()
{
int x = 0; //created in stack
int y = 1; //created in stack
}
As trough Definition stackmemory is "last in, first out" i dont understand how this should work. I can Access "x" which is definately not the variable, which was "last in" in the stack Memory.
private void test()
{
int x = 0; //created in stack
int y = 1; //created in stack
x = 15; //x is not last in (y is last in)!
}
Can somebody explain me, what am i misthinking?