CATEGORII DOCUMENTE |
DOCUMENTE SIMILARE |
||
|
||
A static constructor is a member that implements the actions required to initialize a class. Static constructors are declared using static-constructor-declarations:
static-constructor-declaration:
attributesopt static identifier
( ) block
A static-constructor-declaration may include a set of attributes (17).
The identifier of a static-constructor-declaration must name the class in which the static constructor is declared. If any other name is specified, an error occurs.
The block of a static constructor declaration specifies the statements to be executed in order to initialize the class. This corresponds exactly to the block of a static method with a void return type (10.5.8).
Static constructors are not inherited, and cannot be called directly.
The exact timing of static constructor execution is implementation-dependent, but is subject to the following rules:
The static constructor executes before any instance of the class is created.
The static constructor executes before any of the static members for the class are referenced.
The static constructor executes after the static field initializers (if any) for the class.
The static constructor executes at most one time during a single execution of a program.
The example
class
Test
}
class A
public static void F()
}
class B
public static void F()
}
could produce either the output:
Init A
A.F
Init B
B.F
or the output:
Init B
Init A
A.F
B.F
because the exact ordering of static constructor execution is not defined.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 927
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved