Initialization time for variables like Java Foundation 09

Source: Internet
Author: User

This paper discusses the initialization time of the instance variable, and now the initialization time of the class variable.

The instance variable belongs to the Java class itself, and the class variables of that class are allocated memory space and initialized only when the program initializes the Java class.

From the point of view of the program running, each JVM is initialized only once for a Java class, so every time the Java program runs, the system allocates only one memory space for the class variable once and initializes it once. Fill in the picture abstract (optional)

The commented out code, if executed, runs a program of 3000.

If you put the code under the initial wage, the program runs at 5000?

Salary, the demo is first loaded by the class, in the main method by instantiating the object call Currentsalary, the static object s first assigns the value to Currentsalary 3000, and then Inisalary assigns the value, this time is 5000, The instance object is assigned to Addsalary, and the last currentsalary result is 6000.

Initialization time for variables like Java Foundation 09

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.