A preliminary approach to understanding Java

Source: Internet
Author: User

1. Correctly differentiate functions and methods:

The object-oriented language is called the method, the process-oriented language is called the function, the meaning of the two is the same, but the name is different. Java is an object-oriented language, so use the method.

2. Definition of the method:

It's a code snippet with a name.

3. Purpose of the method:

is for the reuse of code.

The same type of operation does not allow duplicate write code. If you write a lot of similar code in the code, there's a problem with the program you're writing.

4. Composition of the method:

The method modifier list method returns a value type method name (parameter 1, parameter 2, ...). ){

Execute the statement;

}

Comments:

1 The list of method modifiers is optional: permission-controlled: public/protected/private/static, the method modifier list can be omitted.

2 return value type: 11 Any one of the types in the data type

3 no return value type is used with the void,void default to bring return, so return write does not write the same.

4 method name as long as it is a valid identifier
5 method parameter list, multiple comma separated, formal parameter also to indicate data type;
Formal parameter: Refers to those parameters at the function/method definition; Syntax: Data type variable name, data type variable name, ....
Argument: Refers to the parameter passed in at the function call.
6 inside the method body, if there is a return value (type), use the return statement, Syntax: return value; And return is the End function.

5. Invocation of the method:

A. Invocation of a static method: class name. static method name (parameter); assigns the return value to a variable.

B. Invocation of a member method: you first need to assign a new object to the variable and then use the object name. Method name (parameter); Assigns the return value to a variable.

Note: If you call a method in this class in a class, you do not need an object name/class name.

A preliminary approach to understanding Java

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.