Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the execution order of java code blocks?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article is a detailed introduction to "what is the execution order of java code blocks". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "what is the execution order of java code blocks" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

1. Execution flow of static code block, structural code block and structural method of class

Static Code Block> Structure Code Block = Display Initialization (see order)> Structure Method.

Static content is loaded with class loading.

Static code block content takes precedence.

3. Initialize the parent class before initializing the child class.

Order of initialization of class member variables: Explicit initialization is consistent with the initialization level of the structure code block, so the code order determines the initialization order, but note that the structure code block cannot add data types.

examples

class Fu { static { System.out.println("static code block Fu"); } { System.out.println("construct code block Fu"); } public Fu() { System.out.println("constructor Fu"); }} class Zi extends Fu { static { System.out.println("static code block Zi"); } { System.out.println("Build Code Block Zi"); } public Zi() { System.out.println("constructor Zi"); }} class ExtendsTest2 { public static void main(String[] args) { Zi z = new Zi(); }} Read here, this article "java code block execution order is what" article has been introduced, want to master the knowledge of this article also need to practice to understand, if you want to know more about the content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report