What does object initialization do

Source: Internet
Author: User

    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, and
Member 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

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.