A little knowledge of static in Java

Source: Internet
Author: User

Static can modify properties and methods. All static modification methods and properties are related to the class, and are loaded with special processing (including attributes and class priority loading). The difference between the static modifier property and the method is compared below:

First, modify the properties of the time.

1, the use of static modified properties, can be accessed with the object, or can be directly accessed with the class name;

2, when using the static modifier property, the data is the static area of the data segment, and the whole class share a value;

3, in semantics, the attribute is related to the class, not to the object;

4, in the use, is generally constant or the whole class of shared data only with static modification;

Second, the time to modify the method.

1, the use of static modification method, you can use the object to access, you can also use the class name directly access;

2, using the static modification method, can only manipulate the property, call other static methods of the same, and can not use this and super;

3, when used, if a method is only related to the class, and the object is independent of the use of static decoration (most of the tool nature uses static decoration);

4, in the loading time is the priority load;

A little knowledge of static in Java

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.