In this tutorial you will learn
1. Basic structure of a method
2. Input into methods
3. Output from methods
4. How Methods are used in JAVA program
Basic structure of a method
The function in C programming are referred to as Methods in JAVA. They are the set of instruction which are clustered together to perform some specific operation to the input they are given and then the data is returned back to the main of the program or to the Method in which they arr called. The data types of the input arguments and the outputs must be carefully decided because each data type has its cons and pros.
The structure of the method is :
- Access specifier Return Type name_Of_Method( input arguments)
- //body of the method
Each data types has its limitations and advantages like int can only have numbers while char datatype can have numbers and alphabets as well.
This example can give a clearer view
- Access specifier Return Type name_Of_Method( datatype input_argument_1,datatype input_argument_2// .. . . . )
- //body of the method
Outputs from Methods
If the output from the method has to be further used somewhere in program where we just do not display the output rather we make a variable in the main of the program which is equated with the method with the given inputs and it stores the output value in itself. But according to our need if we just want to display, we just use
- Int a;
How Methods are used in JAVA program
The methods in JAVA can be called in main and in other methods as well. The access specifiers are used to limit the access of the methods. Whenever a method having return type void is to be called we do so as
- //calling method in main
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.