An access_specifier
(such as public
). The access specifier controls where this method can be accessed from. Methods should be declared as public if the method needs to be accessed by something other than the object containing the method. If it should only be accessed within the object, you should declare the method as private.
The return_type
of the method such as double
, void
, or DrawingTool
. The return type is the data type that the method sends back to the call of the method. This can be any primitive type or any object that your class knows about. For example, in the CheckingAccount
class, the getBalance
method returns the current account balance, which is a floating-point number, so its return type is double
. The deposit
and withdraw
methods don’t return any value. To indicate that a method does not return a value, you use the keyword void
.
The method_name
(such as deposit
). The name needs to follow the rules of identifiers and should indicate the method’s purpose.
A list of the parameters
of the method. The parameters are the input to the method. The deposit
and withdraw
methods each have one parameter, the amount of money to deposit or withdraw. The type of parameter, such as double
, and name for each parameter, such as amount
, must be specified. If a method has no parameters, like getBalance
, it is still necessary to supply a pair of parentheses () behind the method name.