Java object creation process (from Java programming ideas)

Source: Internet
Author: User

 

To sum up the object creation process, assume there is a class named dog:

1. Even if the static keyword is not explicitly used, the constructor is actually a static method. Therefore, when a dog-type object is created for the first time (the constructor can be regarded as a static method), or the static method or static domain of the Dog class is accessed for the first time, the Java interpreter must search for the class path to locate the dog. class file.

2. Load it into dog. Class (this will be learned later. This will create a Class Object (which is really important) and all the actions related to static initialization will be executed. Therefore, static Initialization is only performed once when the class object is loaded for the first time.

3. When creating an object with new dog (), allocate enough storage space for the dog object on the heap.

4. this bucket is cleared, which automatically sets all the basic types of data in the dog object to the default value (0 for numbers, the same for Boolean and numeric types ), the reference is set to null.

5. Execute all initialization actions that appear in the field definition.

6. Execute the constructor.

Related Article

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.