What does initialization of an object in Java do, with person p = new person ("Zhang San", 20) as an example
First, Person P
1. The compiled Person.class file is loaded in memory first
2. Open space for reference p for class person in stack memory
3. If there is a static member in person, the static variables and methods are loaded into the static method area in the method area first
Second, new person("Zhang San", 20)
1.new keyword to create an object for person in heap memory
2. Load non-static members of person into the method area, andMember variable assignment default value string:null;int:0
3. Initialize the member variable display
4. If there is a construction code block in person, perform the initialization operation in the construction code block first
5. Executing the Construction code block
6. Check if this class inherits from other classes by constructing super () in the code block, and if there is one, initialize the parent class first, and the steps with this class
Same as above
7. Perform the initialization operation in the Construction code block ("Zhang San", 20)
8. Initialization of this object is complete
9. Assign the address value in the heap memory to the reference p (variable) of the person class
Three, above is the object initialization of the approximate process, there is not the right place also please treatise!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
What does object initialization do