Control Statements
Static methods
Code
How to code and call static methods
- To allow other classes to access a method, use the public access modifier. To prevent access, use the private modifier.
- To code a method that returns data, code a return type in the method declaration and code a return statement in the body of the method. The return statement ends the execution of the method and returns the specified value to the calling method.
- Within the parentheses of a method, you can code an optional list of one or more parameters that consist of a data type and name. These values that must be passed to the method when it is called.
- The name of a method along with its parameter list form the signature of the method, which must be unique.
- When you call a method, the arguments in the argument list must be in the same order as the parameters in the parameter list and they must have compatible data types. However, the names of the arguments and the parameters don't need to be the same.