Java basics-day05, java-day05

Source: Internet
Author: User

Java basics-day05, java-day05
1. Method Definition Format and resolution

(1) method Overview: A method is a code block that completes a specific function.

(2) Definition Format:

Modifier return value type method name (parameter 1, parameter 2, parameter 3 ...){

Function body;

Return value;

}

(3) modifier: public class, private class, abstract class, final class.

(4) Return Value Type: used to limit the type of return value.

(5) method name: a name used to call the method.

(6) parameter type: the type of data passed in when the method is called.

(7) parameter name: the variable used to receive the data passed in when the method is called.

(8) method body: code that completes the function.

(9) return: indicates the end method. The return value is sent to the caller.

2. Writing and calling methods

(1) Considerations for defining methods: specify the type of the returned value, specify several parameters, and specify the type of each parameter.

(2) method with return value: Generally, it is called by value assignment, for example, int s = sum (a, B). It is meaningless to call it separately. You can call System by means of output. out. println (sum (a, B ));.

(3) void modification method: no clear return value can only be called separately.

(4) method overloading: in the same class, more than one method with the same name is allowed, as long as their parameter numbers or types are different. It is irrelevant to the type of the returned value. Only the method name and parameter list are available. During the call, JVM uses different parameter lists to differentiate methods with the same name.

3. method parameter transfer:

(1) form parameter: The variable used to receive the actual data.

(2) actual parameters: the variables involved in the calculation.

(3) When a parameter is of the basic data type: the change of the form parameter does not affect the actual parameter.

(4) When a parameter references a data type: Changes in the form parameter directly affect the actual parameter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.