Java Reference
In-Depth Information
Java console
26
printSums
printSum
c 36
b 20
c 6
b 20
We have carried out the first step of assigning the arguments 20 and 36 to the
parameters. Notice that there are 2 b 's and 2 c 's in the picture. These variables
are independent of each other.
We now execute the statement in the body of procedure printSum , printing
56 in the Java console:
Java console
20
56
printSums
printSum
c 36
b 20
c 6
b 20
Execution of the call to printSum is finished, so we erase the box. We are
now in this state:
Java console
20
56
printSums
c 6
b 20
We summarize:
To step over a call , execute it as an individual action, doing what the
specification of the method does. The method being called is a black box
into which we cannot look, and we rely only on its specification.
To step into a call , (1) draw the parameters of the method, (2) assign the
arguments of the call to the method, (3) execute the method body, and (4)
erase the parameters of the method.
Suppose you are executing a program yourself, or you are using a debugger,
presumably to find an error in the program. Which of these two ways you use to
execute a call will depend on the situation. If you are 100% sure that a method
is correct, you can step over a call to that method. However, if you believe an
error may be in a particular method, step into calls to it.
2.3.3
Conditional statements and blocks
The body of a method is a sequence of statements, which are executed in the
order in which they appear. So far, we have seen assignments and procedure calls
as statements that can appear in a method body. We now introduce three more
kinds of statement: the if-statement, the if-else-statement, and the block. The if-
statement and if-else-statement are examples of conditional statements .
Search WWH ::




Custom Search