Get the App
SLTechnology News&Howtos  ›  Development  › 

What does the method in Java mean?

Shulou Source: shulou.com Published: 2022-06-03 11:12:45 10月06日 Update

This article is to share with you about what the method in Java means. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Statement blocks (sometimes called compound statements) are any number of simple Java statements expanded with curly braces. Block determines the scope of the local variable. The program code in the block, as a whole, is executed together. Blocks can be nested within another block, but variables with the same name cannot be declared within two nested blocks. Statement blocks can use external variables, while external variables cannot be used outside, because the scope of variables defined in statement blocks is limited to statement blocks.

Methods in Java

A method is a code snippet used to perform a specific function, similar to a function in other languages.

Method is used to define the behavioral characteristics and functional implementation of the class or an instance of the class. A method is an abstraction of the behavioral characteristics of classes and objects. The method is very similar to a procedure-oriented function. In the process-oriented process, the function is the most basic unit, and the whole program is composed of function calls. In object-oriented, the basic unit of the whole program is the class, and the method is subordinate to the class and object.

Method is called:

Object name. Method name (argument list)

A detailed description of the method

Formal parameter: used to receive incoming data when the method is declared.

Argument: the data actually passed to the method when the method is called.

Return value: the method returns data to the environment in which it is called after execution.

Return value type: the pre-agreed data type of the return value. If there is no return value, it must be specified as void.

Overloading of methods in Java

Method overloading means that multiple methods with the same name but different parameters can be defined in a class. When called, the corresponding method is automatically matched according to different parameters.

Minefield

The method of overloading is actually a completely different method, but with the same name!

The conditions that make up the method overload:

1. Different meanings: the type, number and order of formal parameters are different.

two。 Only different return values do not constitute the overload of the method.

Thank you for reading! This is the end of this article on "what is the meaning of the method in Java". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Methods statements different variables functions data parameters objects programs types formal parameters meaning same code function content function unit actual more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi MySQL macOS Linux