Class execution sequence, final usage, and execution sequence final usage

Source: Internet
Author: User

Class execution sequence, final usage, and execution sequence final usage

---------- Java class initialization sequence -----------
1. Static variables
2. Static code block
3. main Method
4. class attributes
5. Code Block
6. Constructor


------ If there is a parent class, it is :---------
1. parent class-static variables
2. parent class-static code block
3. Subclass-static variables
4. Subclass-static code block
5. parent class-attributes
6. parent class-code block
7. parent class -- Constructor
8. Subclass-attributes
9. Subclass-code block
10. Subclass-Constructor

Note:
1. If the Test class has a static code block or static attribute, the main () method is executed only when all the static variables and static code blocks of the Test class have been loaded.
2. The static code segment is executed only when the class is loaded for the first time.

* ------------- Final: Finally -------------------
* 1. The variable modified with final is a constant.
* 2. The value of the reference type (such as object) modified with final can be changed, but it cannot be new.
* 3. The final modification method cannot be rewritten.
* 4. Classes modified with final cannot be inherited.
*/

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.