Function
- It is a collection of statement that performs an specific task.
- It executes when it is called by its name.
- A large program is devided into a number of small building block for simplicity and this building block is called function.
- We can call a function again and again.
- The most importent features of function is code reusability.
- The JAVA library provides many pre-defined functions.
Syntax of function
Access Specifier
- It is a keyword which is used to provide accessibility of function.
- There are three access specifier are used in java public,private and protected.
- It is such type of element which indicates that which type of value is returning by this function.
- If we do not want to return any value then we use void keyword in place of return_type.
- It is the actual name of the function.
- It is also used at the time of calling the function.
- It is the place where we can pass a number of parameter/variable.
- These variables may be used in the program.
- The value of parameter is passed from the calling of function.
- It is optional part.
- It is the place where the actual code is written to perform the specific task.
Types of Function
There are two types of function in java.- Predefined Function
- Userdefined of function
- The function which is predefined in the library is called predefined function.
- Exa.of predefined function are print,println,nextInt,nextFloat etc.
- The function which is made by the user is call userdefined function.
- add,sub,multiply,div etc userdefined name.
Function with no return type and no parameter
Function with no return type and with parameter
Function with return type and no parameter
Function with return type and with parameter
0 Comments