Java initialization process

Source: Internet
Author: User
Tags export class

1. Class Members are automatically initialized. The basic type is always initialized to 0 first (boolean is false, (char) 0), and the object reference is initialized to null;
2. Specify initialization for class members. You can initialize basic and non-basic type objects in the class member definition or constructor (including other methods), but this does not prevent automatic initialization from starting first;
3. the initialization sequence is determined based on the sequence defined by class members;
4. Static members will be initialized only when they are accessed for the first time (class objects are loaded for the first time) and will not be initialized after that. The initialization sequence is static first and non-static;
5. initialization of the export class is the process from the base class (top layer) to the export class, which is initialized sequentially.
6. Call Sequence of the constructor
A. Before any other event occurs (when the class object is loaded), the bucket allocated to the object is initialized to a binary value of 0 (refer to 1)
B. Call the base class Constructor (for class initialization, refer to 1 ~ 5 );
C. initialize class members in declared order;
D. constructor of the call class;
E. This is a recursive process, starting from the root until the bottom-layer export class.
7. Object clearing is in the opposite order of initialization.
8. Compile a beneficial rule of the constructor to make the object normal in the simplest way possible. If possible, avoid calling other methods. The only method that can be safely called in the constructor is the final method in the base class (also applicable to private methods ).

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.