Object initialization

xiaoxiao2021-03-06  74

For initialization mainly includes these aspects: static variable, Non-Static variable, constructor, new object is established.

1. Initialization of Static Variable: When the PULIC CLASS is loaded, it will begin to initialize the Static variable because the reference of the Static variable is stored in Static Storage (static storage). There is no initialization of the Non-Static variable and constructor, because there is no object of the object, just put a certain type loadin. Note that only the Static variable is only initialized once, when there is a new object generated, he will not be reopened, that is, his REFRENCE has been fixed, but his value can be changed.

2. When an object is generated, the Non-StATIC variable in this Class (Type) is started to initialize, and then the constructor is initialized. Generate an initialized Object object.

3. Perform other functions in order.

4, for inherited Class (type): derivedclass2, derivedclass1, baseclass; because of the inheritance relationship between them, if you want to Laodin DerivedClass2, you must first loadin deiveClass1, if you want Laodin DerivedClass1, first loadin baseclass. That is, the Laodin sequence is: baseclass, derivedclass1, deriveclass2 ..., whenever loadin is a Class, press "First" to initialize (initialize the Static variable in the Class).

5. When using the inheritance Class When using the NEW, press BASECLASS, DERIVEDCLASS1, DERIVECLASS2 ..., and each class is initialized in each class. Note that the constructor of Derived Class must meet Baseclss to be initialized.

Overall thought: static variables ... Non-static variables ... constructor.

转载请注明原文地址:https://www.9cbs.com/read-90434.html

New Post(0)