Methods
A block of statements that have the access modifier, name, return type, and parameters (which may or may not be there) are nothing but a method. A method is meant to perform some tasks.
Note
Methods are meant to call either by another method or by another program.
How to use a method?
As said earlier, methods are meant to perform some actions. So, any method or program that needs to utilize these actions could call/consume/use the defined method.
A method has various element discussed as follows:
- Access modifier: A method should have an access modifier (refer to the previous section for more details on modifier). The modifier helps us define the scope of method or the availability of the method, for example. A method defined using the
private
modifier can only be visible to its own class. - Return type: After performing an action, a method may or may not return something. Method return type is based on the data types (refer to day two for information on datatypes). For example, if method...