Java Foundation--day05

Source: Internet
Author: User

1. Method definition Format and Analysis

(1) Method Overview: A method is a block of code that accomplishes a particular function.

(2) Define the format:

Modifier returns a value type method name (parameter 1, parameter 2, Parameter 3 ...) {

function body;

return value;

}

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

(4) Return value type: The type used to qualify the return value.

(5) Method name: a name that is used to invoke the method.

(6) Parameter type: The type of data that is passed in when the method is called.

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

(8) Method body: The code to complete the function.

(9) Return: Ends the method and brings the return value to the caller.

2, the method of writing and calling

(1) Considerations for defining a method: The type of the explicit return value, the explicit number of parameters, and the type of each parameter.

(2) method with return value: general assignment invocation, e.g. int s = SUM (a, b); The call to System.out.println (A, b) can be made by making an output call without meaning.

(3) Void-Modified method: There is no explicit return value and can only be called separately.

(4) Method overloading: In the same class, more than one method of the same name is allowed, as long as the number or type of their arguments is different. Regardless of the type of the return value, look only at the method name and the parameter list. Called when the JVM distinguishes a method with the same name by different argument lists.

3, the method of parameter delivery:

(1) Formal parameters: variables used to receive actual data.

(2) Actual parameters: the variables that are actually involved in the operation.

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

(4) When the parameter is a reference data type: The change of formal parameters directly affects the actual parameters.

Java Foundation--day05

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.