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