C # Keywords of language learning

Source: Internet
Author: User

Static Modifier

 

Declares that a class member belongs to a class rather than an instance of the class.
 

StaticModifier indicates that the member belongs to the instance of the class rather than the class. Even if multiple instances of the class are created, the specified application only exists.StaticA copy of the member. You can only accessStaticMember. However, in the class member declaration, you canThisObject To accessStaticMember.

Class Members can useStaticModifier. Class, interface, and interface members cannot useStaticModifier.

You cannot setStaticModifier and any inheritance modifier (AbstractAndFinal) Or version Security modifier (HideAndOverride.

Do not setStaticThe modifier is the sameStaticStatement obfuscation.StaticModifier indicates a member of the class itself (not any class instance.
The following exampleStaticModifier usage.
Class CTest {
Var nonstaticX: int; // A non-static field belonging to a class instance.
Static var staticX: int; // A static field belonging to the class.
}

// Initialize staticX. An instance of test is not needed.
CTest. staticX = 42;

// Create an instance of test class.
Var a: CTest = new CTest;
A. nonstaticX = 5;
// The static field is not directly accessible from the class instance.

Print (a. nonstaticX );
Print (CTest. staticX );

The output of this program is:
5
42

Related Article

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.