Static initializer)

Source: Internet
Author: User

I have read such a statement in the book before. I still don't know why. I finally understood it after reading headfirst Java today.


Just like static variables, static initializer is a piece of program code that will be executed when the class is loaded. It will be executed before other programs can use this class,Therefore, it is suitable for the starting program for storing static final variables.


Public class Hello {private final static int I; static {I = 1;} // equivalent to // Private Final Static int I = 1; but it is more clear, especially for multiple final variables, public static void main (string [] ARGs) {system. out. println ("" + I );}}


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.