21st Lesson object's Construction order

Source: Internet
Author: User

1. Order of construction of objects

(1) for a local object : Constructed when the program execution Flow arrives at the object's definition statement

The construction order of the "instance analysis" local objects

(2) for heap Objects

① creating an object when the program execution flow arrives at the new statement

② using new to create an object will automatically trigger the call of the constructor

Construction order of the "programming Experiment" heap object

(2) for global Objects

The order in which the ① objects are constructed is indeterminate

② different compilers use different rules to determine the construction order

The construction order of the "instance analysis" global object

2. Summary

(1) The construction order of local objects depends on the execution flow of the program

(2) The construction order of heap objects depends on the order in which new is used

(3) The construction order of global objects is indeterminate

21st Lesson object's Construction 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.