Java Reference
In-Depth Information
CHAPTER
5
Methods
The behaviors of an object are represented as methods in a class. In this chapter,
we will discuss the details of methods in Java, including the signature of a
method, invoking a method, and how data is passed back and forth between
method calls.
Method Call Stack
I want to begin with a discussion on how methods change the flow of control
of a program. A method is invoked (also referred to as called ), which causes flow
of control to jump to the method that is being invoked.
Flow of control then executes the statements within the method. Of course,
the method being executed might invoke another method, causing flow of
control to jump to this other method. All method calls are maintained in a
structure known as the call stack . The current method that is executing is at the
top of the call stack. When this method completes executing, it is removed
from the top of the call stack, and the flow of control returns to the previous
method on the stack. When a new method is invoked, this new method gets
placed at the top of the call stack.
107
Search WWH ::




Custom Search