In Java, methods and local variables (that is, variables declared in a method) are placed on the stack memory. When you invoke a method, the method is placed at the top of the stack on the call stack. The method at the top of the stack is the method that is currently executing until execution is complete before it is released from the top of the stack. We know that stacks are a data structure that performs "advanced out-of-date". I'll give you some practical examples below. Look at the code first.
public void Graduate ()//First method
{
Study ();
}
public void Study ()//A second method
{
Readbooks ();
}
public void Readbooks ()//third method
{
Boolean done = true;
}
The first method will call the second method in the execution process, at this time, the first method in the stack is pressed below, the second method into the stack, placed on top of the stack, the second method at the time of execution call the third method, at this time, the second method is pressed into the following, the third method into the stack, as to the top, The method at the top of the stack is currently being executed.
Call the first method
| Graduate () |
Call a second method
| Study () |
| Graduate () |
Call a third method
| Readbooks () |
| Study () |
| Graduate () |
When the third method finishes executing
| Study () |
| Graduate () |
In-memory representation of method invocations in Java