The initialization time of the variable of Java Foundation

Source: Internet
Author: User

For instance variables, it belongs to the Java object itself, and each time a program creates a Java object, it needs to allocate memory space for the instance variable and perform the initialization.

From the point of view of the program's operation, each time a Java object is created, it allocates memory space for the instance variable and

Initialization of the row.

A program can Initialize instance variables in 3 places :

. specifying an initial value when defining an instance variable ;

. specifying an initial value for an instance variable in a non-static initialization block ;

. When an instance variable specifies an initial value in the constructor .

Whenever a program invokes a specified constructor to create a Java Object, the constructor is bound to get an opportunity to execute. In addition, the non-static initialization blocks contained in the class are given an opportunity to execute and are always executed before the constructor executes.

The effect is as follows:



The initialization time of the variable of Java Foundation

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.