Home > Java > JavaBase > body text

How to define functions in java

王林
Release: 2019-11-13 09:23:47
Original
6132 people have browsed it

How to define functions in java

Concept of function:

A function is an independent block of code defined in a class to implement a certain function. In Java, functions are also called methods. The main purpose of functions is to improve code reusability. Functions are all run in stack memory, and the running function is on the top of the stack.

Function format:

修饰符    返回值类型    函数
名  (  [    参数类型1 参数名1,参数类型2 参数名2....    ]  ){

                   //   [    ]    里面表示可选项,即参数不是必须的

                   执行语句...

                   return  返回值;    //返回值的类型必须与返回值类型一致

                    }
Copy after login

Description:

Modifier: It can be an access modifier or It is said to be function modifiers (abstract, final, static, synchronized), or a combination of the two.

Return value type: The data type used to limit the function return value.

Parameter type: used to limit the data type passed when calling the function.

Parameter name: It is a variable used to receive the data passed when calling the method.

return: Used to receive methods and return values ​​of the specified type from the function.

Return value: This value will be returned to the caller of the function.

Recommended tutorial: Java tutorial

The above is the detailed content of How to define functions in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template