CSE 174 Chapter Notes - Chapter 5: Local Variable, Top-Down And Bottom-Up Design, Return Statement
Document Summary
Packages a computation consisting of multipole steps into a form that can be easily understood and reused. You call a method in order to execute its instructions methodname(); fill in the parentheses with any parameters (inputs). As a user of the method, you don"t need to know how it functions, just the specifications (black box). Use example of calculating the volume of a cube with given side length. Public static double cubevolume(doublesidelength)- this line is called header. Next specify body, or statements executed when method is called. Parameter variables- variables created for receiving the method"s arguments. Values supplied to the method are called arguments. Return statement is used to specify result of method. When return statement is processed, method exits immediately. Can return variable or value of any expression. Some programmers dislike using return multiple times in a method. Instead, store method result in a variable that you return in the last statement of the method.