Java Class Execution order

Source: Internet
Author: User

1. Perform static member assignments and static initialization blocks if the parent class has static member assignments or static initialization blocks
2. Perform static member assignments and static initialization blocks if the class has static member assignments or static initialization blocks
3. Assign the member of the class to the initial value (the values of the members of the original type are the specified values, for example, the int type is 0,float type is 0.0f,boolean type is false; The initial value of the object type is null)
4. If there is a this () call in the construction method (which can be another call of this () with parameters), execute it and proceed to the 7th step after execution, and proceed if there is no this call. (There is a possibility of recursive invocation of other constructs)
5. Perform an explicit super () call (which can be another super () call with parameters) or an implicit super () call (the default constructor method), which goes into the construction of a parent class and pushes up to the object's construction.
6. Execute the member assignment and initialization block in the class declaration.
7. Execute other statements in the constructor method.

The final simplified sequence version is:

1. Static member assignments and static blocks of the parent class
2. Static members and static blocks of subclasses
3. How to construct a parent class
4. Member assignments and initialization blocks of the parent class
5. Other statements in the constructor method of the parent class
6. Member assignments and initialization blocks for subclasses
7. Other statements in the construction method of a subclass

Java Class Execution order

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.