Home >Java >Javagetting Started >What is the method in java

What is the method in java

(*-*)浩
(*-*)浩Original
2019-11-12 10:02:253203browse

What is the method in java

#A Java method is a code block that can be called repeatedly to implement a specific function.

The definition of a method includes two parts: method header and method body. (Recommended learning: java course )

方法头{
具体的内容
}

Method header can consist of the method of method, the brackets and parameters after the name and name.

If the method header has parameters:

int but(int a,int b){
return a*b;
}

The method header without parameters:

int  but()
{
return 0;
}

Method body It consists of a pair of brackets and the content between the brackets. The content includes java statements and variable declarations (referring to local variables).

Such as:

int sum()
{
    int N;
    for(int n;n<=100;n++)
    {
        N=N+n;
    }
    return N;
}

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

Statement:
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
Previous article:what is java reflectionNext article:what is java reflection