Java (12th chapter)

Source: Internet
Author: User

12th Chapter

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 (initial value is different, scope is different)

2.1 member variables, with default values

Called directly through the member variable name in the current class, and in other classes, by the object name of the class. Property (member variable) name, member variable name 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 Annotation (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.

Definition and invocation of the null parameter method in Java (Methods include: Method Name, Method return value type, method body)

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-

L Call methods of other classes: Object name. Method Name ();

L 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 ());

Four, object-oriented 3 characteristics: encapsulation, inheritance, polymorphism

Five, object-oriented advantages:

Consistent with human thinking habits; information hiding, improve the maintainability and security of the program;

Improve the reusability of the program.

One of the basic principles of OOP is that a computer is composed of a single unit or object that can act as a subroutine, and this architecture programming is a powerful function of reusability, flexibility, and extensibility.

Java (12th chapter)

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.