In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use the code block in java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Overview
The code block is also a member of a class (that is, part of a class), similar to a method that encapsulates logical statements in the method body and is surrounded by {}. Called implicitly when the class is loaded or when the object is created.
The following is an overview of the format and detailed parsing of the main code blocks:
two。 Main application order:
Analyze the application scenario: when the class needs to do something necessary, it can be done by putting it in the code block, rather than by putting the same statement into each constructor.
Application order: no matter when you create an object, the content in the code block is called first. Here, when you use the code block, the code block will be called automatically when you need to call the constructor.
3. Discussion on matters needing attention and details of Code Block
Static code block:
static code block, also called static code block, initializes the class and executes only once when the class is loaded. A normal code block is executed every time an object is created.
picture description:
Main details of the code block:
where: a normal code block is called only when the object is created, and it is called each time it is created. Class is not executed when the class is loaded.
The most important thing about is the static code block in a class. Static attributes are initialized with the same priority, and if there are more than one, they are called in order of definition. The same is true for normal code blocks and normal attribute initialization. Static takes precedence over normal, followed by constructors.
is mainly about accessing the constructor of the parent class first in the constructor of a class, then accessing the normal code block of the class, and finally executing the code of the constructor.
is mainly about the order in which a subclass object is called when creating a subclass object.
is mainly about calling only static members (static attributes and static methods) in static code blocks, while ordinary code blocks can call static and non-static ones.
The above is all the contents of the article "how to use Code blocks in java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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: 263
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.