Method Definitions
Subprograms in Java are called methods. The definition format is
- Modifiers Returntype Methodname ( Parameterlist )
- {
- declarations and statements
- }
The parameter list contains the types and names of all the parameters.
The declarations and statements are called the body of the method. Parameter names and variables declared in the body are local to it.
Control returns from the methods either when the body is finished execution or a return statement is encountered. Return statements may also return a result.
Parameters of primitive types are passed by value, of class types by reference.