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