A brief talk on methods and method overloading in Java

Today, let's talk about methods and method overloading in Java and some points that need attention;

method:

The method of Java is similar to that of other languages. It is a code fragment used to complete specific functions,

Declaration format:

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

Formal parameter: used to accept external input data when the method is called;

Argument: data passed from the world to the method when the method is called;

Return value: the data returned to the calling environment after the method is executed;

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;

In the Java language, methods are called in the following form: object name Method name (argument list);;

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

Return statement terminates the operation of the method and specifies the data to be returned;

Note: the basic data type passes the data value itself, and the reference data type passes the reference to the object, not the object itself;

Method overload:

That is, the method name is the same, the number and type of method parameters are different, and different functions are distinguished by different number and type;

Method overloading has nothing to do with the return value type and modifier. Java overloading occurs in this class. The overload conditions are that multiple method names in this class are the same,

However, different parameter lists (possibly different number of parameters and different parameter types) have nothing to do with the return value;

The above article briefly talks about methods and method overloading in Java, which is all the content shared by Xiaobian. I hope it can give you a reference and support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>