Home > Java > Javagetting Started > body text

What is the method in java

(*-*)浩
Release: 2019-11-12 10:02:25
Original
3110 people have browsed it

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 )

方法头{
具体的内容
}
Copy after login

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;
}
Copy after login

The method header without parameters:

int  but()
{
return 0;
}
Copy after login

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;
}
Copy after login

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!

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