Java: Member variables, local variables, and static variables

Source: Internet
Author: User

Comb:

Depending on where you define the variables, you can divide the variables into two main categories: member variables and local variables.

member variables (commonly known as global variables): variables defined in a class. is divided into instance variables and class variables (also become static variables).

instance variable: without static decoration, you need to instantiate the class before it can be accessed through the instance, and you cannot access the instance variable through the class. Instance variable, which means that the program can access the instance variable of the instance as long as the instance exists.

class variable: modified with static, the program can access class variables of the class as long as the class exists

The following example describes access rules for static inner classes and instance variables and class variables for this class:

Local variables: variables defined in the method. According to the definition of different forms can be divided into three kinds: formal parameters, method local variables, code block local variables

Parameter : the variable defined when defining the method signature, the scope of the formal parameter is valid throughout the method;

method local variable: a local variable defined in the body of a method, scoped from the place where the variable was defined, to expire at the end of the method;

code block local variable: a local variable defined in a code block where the scope of the local variable takes effect from where the variable is defined, with the end of the code block invalidated.

Static variables are variables that use static modifiers, which are a one-to-a-kind relationship with class variables???

Answer: Yes, refer to https://www.douban.com/note/513499371/

Java: Member variables, local variables, and static variables

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.