Java Learning (10)

Source: Internet
Author: User

The scope of the variable (valid scope of use)

1. There are 2 kinds of variables

1.1 member variables (attributes)

declaration in the inside of the class, outside of the method

1.2 Local variables

Declared within a method or for loop structure

2. Considerations when calling

2.1 member variables, with default values (uninitialized), are called directly through member variable names in the current class, and in other classes through the object name of the class. The name of the member variable is unique within the same class.

2.2 Local variables, no default values, must be assigned before use

Local variables, which can only be used in the current method, other methods and other classes cannot be called; names are unique in the same method, but multiple methods allow local variables with the same name

2.3 Local variables have precedence over member variables when local variables and member variables have the same name

Second, Java Document Comments (Javadoc) automatically generated

1, single-line comment://

2. Multi-line Comment:/* */

3. Document Comment:/** */

Steps:

After you select the item, right-click and select Export ..., 4 radio buttons, select the package, and finally click Finish to complete the build of the Help document HTML file, which is saved by default in the Doc folder under the current project.

Third, the definition and invocation of the non-parameter method in Java

1, the role of the method

Encapsulation (duplicated code)

Improve code reusability, maintainability

2, how to define the method of non-parameter _ methods named followed by camel nomenclature

Public return type method name () {

............... Method body

}

3, according to the return type, no parameter method, divided into 2 kinds

3.1 There is a return type (data type), in the method body, must appear

Return "expression, variable, value", return written in the last line of the method

3.3 There is no return type, when the method is defined, the return type is write void, there is no return statement,

Output results (SYSTEM.OUT.PRINTLN)

4. Method Invocation-

Methods for calling other classes: Object name. Method Name ();

A call between methods in the same class: Method name ();

4.1 No return type

The name of the object. Method name ();//Output data

4.2 has return type

Data type variable name = Object name. Method Name ();

SYSTEM.OUT.PRINTLN (variable name);

or System.out.println (object name. Method name ());

Iv. Object-oriented 3 Big features: encapsulation, inheritance, polymorphism

Java Learning (10)

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.