The difference between a Java member variable and a local variable modifier

Source: Internet
Author: User

Member variables:

Can be public,static, protected,default,final modified.

Local variables: Both in the method and in the code block (static and non-static)

Can be modified by default, final

Reference:

Baidu Search: Code blocks and member variables

Initializing static member variables in a static code block in Java
Share | 2015-12-31 22:18∮ old boy, | View 56 Reward: 5
Java
static{
Age = 2;
}
static int age = 4;

I put the statement of age statement behind the code block, why did not error, when the code block execution time should not be declared AH?
2015-12-31 22:28 User Acceptance
Static variables can only be defined inside a class, not defined in a static block or method can be defined inside a static variable within the class, initialization in a static block, because the inside of the class is not allowed to have an operation statement, such as JDBC operation, so can be in static block static{} initialization operation, For example, JDBC defines static variables primarily for external access, defines a local outside of which there is no access, why it is defined, and cannot define

The difference between a Java member variable and a local variable modifier

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.