Order of various property invocations in Java

Source: Internet
Author: User

The static method is executed when you call it manually.

Static variables are loaded with the class, with the highest precedence. Class loading executes

Then there is the static initializer (only static member variables are initialized ). class loading executes

Then, the property is initialized (only non-static member variables are initialized). New object is executed when the

Finally, the constructor. The new object is executed.


Object creation Process:

For the first time (new creates an object or calls a static property or static method), find the classpath to locate the class file, load the class file, and initialize all the static properties.

Second, only when the object is created, the storage space is opened up, and then the storage space sets the default value for the object and then initializes it according to the field setting value.

Last execution constructor

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Order of various property invocations in Java

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.