Thinking in Java [Java programming mechanism] learning notes-initialization order of initialization

Source: Internet
Author: User
First

The initialization sequence is related to the declared sequence of variables, and the initialization of variables (including primitive types and Object Reference) must be before all methods are called, and even the constructor must be later.

Static Data initialization static data initialization all static data is stored in a storage area, and Initialization is only performed once. The initialization order is as follows: 1. static (if initialization has passed, the initialization will not be repeated) 2. non-static but there is a saying in the book: "static data are initialized only when the first XX object is created or the first static access occurs" That is to say, static variables are not initialized when they are not required. It is not necessary to create an object for a class or to use a class. staticvariable access. Explicit static statement initialization explicit static initialization syntax: static {
// Clses ...} the initialization sequence is the same as that of static variables. If you create a class pair or access a static variable in the class, the explicit statements in the static domain will be triggered by non-static instance initialization syntax :{ Clauses...} instance initialization always completes the statements in parentheses before calling the constructor.

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.