Member variables and local variables, member variables local variables

Source: Internet
Author: User

Member variables and local variables, member variables local variables

In java, variables can be divided into two categories based on their locations: member variables and local variables.

Member variables are defined in the class, including:

1. Class variable: modified in static mode. Scope: It exists from the preparation stage of the class until the system completely destroys the class. Same as the survival scope of the class

2. instance variable: not modified in static mode. Scope: The instance variable of the class starts to exist when it is created until the system completely destroys the instance. Same as the survival range of the corresponding instance

Class Test {

// Define instance variables
Public String name;
// Defines a class variable public static int price ;}

 

Local variables refer to the variables defined in the method, including:

1. form parameter: The variable defined in the method signature. Scope: valid throughout the method.

2. Local variables of the method: the local variables defined in the method body. Scope: The local variables take effect from the place where the variable is defined and expire at the end of the method.

3. code block local variable: The local variable defined in the Code block. Scope: takes effect from the place where the variable is defined until the code block ends.

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.