Class initialization
- Class initialization is performed <clinit> () method, which code consists of two parts:
- (1) explicit assignment of static variables
- (2) static code block
- Talia is assembled in the order written
- Class initialization method for each class only once
- Subclasses will check the initialization parent, if the parent class has not been initialized, the initialization will first complete the parent class, which is to run a parent <clinit> () method
Examples of initialization
- A class may be 1 ~ n th <init> method, there are several see declares several constructors
- Examples of the initialization is performed corresponding <init> method, which perform particular, to see which calls back new constructor
- Examples initialized by about four parts:
- ①super () or super (argument list) ==> instance initialization method corresponding call parent class, description when creating a subclass object instance of the parent class also cause the initialization method performed
- Where the super () or super (argument list) was originally written in the first line of the constructor
- Explicit assignment ② instance variables
- ③ non-static block
- ④ constructor code
- Wherein ② and ③ are written sequentially by the code assembly, ① and ④ is a one
- Examples of the initialization is performed each time the object is new, a new performing a
Class and instance initialization Initialization
If the first use of a class is created in the object, first class initialization is completed, then perform instance initialization