Please enable JavaScript.
Coggle requires JavaScript to display documents.
Ch 5 - methods (implementation (Pick a name for the method (cubeVolume).,…
Ch 5 - methods
implementation
-
Declare a variable for each argument (double sideLength). These variables are called the parameter variables.
-
Add the public static modifiers. We will discuss the meanings of these modifiers in Chapter 8. For now, you should simply add them to your methods.
-
the details
-
-
Methods can receive 0 to multiple arguments, but they return only one value
parameter passing
-
-
Many programmers dislike the use of multiple return statements in a method. You can avoid multiple returns by storing the method result in a variable that you return in the last statement of the method
stubs
You often need to test a method that calls another, but the other method hasn’t yet been implemented. Then you can temporarily replace the missing method with a stub
-
-
method comments
-
Java language provides a standard layout for method comments, called the javadoc
/* Computes the volume of a cube. param sideLength the side length of the cube return the volume /
-
-
return values
-
When the return statement is processed, the method exits immediately
what they are
A method packages a computation consisting of multiple steps into a form that can be easily understood and reused.
-
-
-
recursive method
a meth that calls itself
- Every recursive call must simplify the task in some way.
- There must be special cases to handle the simplest tasks directly.