Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In Chapter 6, the stack data structure was introduced in the context of understanding how Java performs method calls. We discussed both the method-call stack (also known as the program-execution stack) and activation records. In this section, we’ll use these concepts to demonstrate how the program-execution stack handles recursive method calls.
Let’s begin by returning to the Fibonacci example—specifically, calling method fibonacci with the value 3, as in Fig. 18.6. To show the order in which the method calls’ activation records are placed on the stack, we’ve lettered the method calls in Fig. 18.7.