Non-static and static initialization blocks

Source: Internet
Author: User

1 Operations on Property assignment: (1) default initialization (2) explicit initialization or code block initialization (here two structures are executed sequentially) (3) in the constructor

(4) Modify the corresponding properties of the object by means of the method

2 initialization block (code block): If there is a decoration, you can only use static

3 non-static code block: (1) You can initialize the properties of a Class (2) You can have output statements

(3) A class can have multiple non-static code blocks, executed sequentially (4) Every object that creates a class, a non-static block of code is created once (5) It executes earlier than the construction method

4 Static code block (1) There can be output statements (2) with the class loaded, can only be loaded once

(3) executed sequentially, before non-static code block (4) static code block cannot execute non-static methods and properties

Non-static and static initialization blocks

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.