The creation process of Java objects

Source: Internet
Author: User

The order of initialization is first static (if they have not been initialized by the previous object, that is, when the new object is initialized), the variable initialization order has variables in the class definition order;

object creation process, take the dog class as an example:

1. The Java compiler must find Dog.class when the first stati of the dog is created, or when the Stajitic method/static field of the dog class is accessed;

2. When Dog.class is found (it creates a class object), all of its static initialization modules will run. Therefore, static initialization occurs only once-----when the class object is first loaded

3. When creating a new dog (), the build process of the dog object allocates enough memory space for a dog object in the memory heap (heap) first;

4. This space is 0, and all the basic types in dog are set to their default values;

5. All initialization occurs when the field definition is performed;

6. Execute the constructor

The creation process of Java objects

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.