Home > Java > javaTutorial > body text

Detailed introduction to methods and method overloading in Java

黄舟
Release: 2017-09-20 09:50:27
Original
1075 people have browsed it

The following editor will bring you a brief talk about methods and method overloading in Java. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

Today we will talk a little about methods and method overloading in Java and some things that need attention;

Method:

Java’s method is similar to functions in other languages. It is a piece of code used to complete a specific function.

Declaration format:

[Modifier 1 Modifier 2 ....], return value type method name (formal parameter list) {Java statement: - - -}

Formal parameters: in the method Used to accept data input from the outside when calling;

Actual parameters: The data passed to the method by the world when calling the method;

Return value: After the method is executed, it is returned to the environment in which it was called. Data;

Return value type: The data type of the return value agreed in advance. If there is no return value, the return value type void must be given;

The Java language uses the following form to call methods: Object name. Method name (actual parameter list);;

The number, data type and order of actual parameters must match the formal parameter list declared by the called method;

The return statement terminates the method Run and specify the data to be returned;

Note: The basic data type transfers the data value itself, and the reference data type transfers a reference to the object,,, rather than the object itself;

Overloading of methods:

means that the method names are the same, but the number and type of method parameters are different. Different functions are distinguished by the difference in number and type. ;

Overloading of methods has nothing to do with return value types and modifiers. Java overloading occurs in this class. The condition for overloading is that there are multiple methods with the same name in this class.

But the parameter list is different (maybe, the number of parameters is different and the parameter type is different) has nothing to do with the return value;

The above is the detailed content of Detailed introduction to methods and method overloading 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