In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "example Analysis of java-related problems". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "java-related problems with examples"!
1. Question public class Test {
Public static Test T1 = new Test (); / / Mark 1
{
System.out.println ("block A"); / / tag 2
}
Static {
System.out.println ("block B"); / / Mark 3
}
Public static void main (String [] args) {
Test T2 = new Test (); / / Mark 4
}
Second, the loading order of knowledge point class 1. Parent static object and static code block 2. Subclass static object and static code block 3. Parent class non-static object and non-static construction code block 4. Parent constructor 5. Subclass non-static objects and non-static construction to code block 6. Subclass constructor 7. Common code block 8. In the above loading order, the static blocks of code in the class are executed in declarative order, and 1 and 2 are executed when the class is loaded into the method area, that is, it does not need to be executed when the new instance is called. Third, answer analysis
First go to the Test class, without a parent class, then execute your own static objects and blocks of code, and execute them in declaration order. So first, the static object marked 1 is executed and instantiated, so the corresponding construction code block is called, and the statement marked 2 is executed, so block An is outputted; after execution, the static code block, that is, the statement marked 3, is executed sequentially, so block B is output Continue to execute the static main method, re-instantiate the Test object, call the construction block again, and output the statement marked 2 again, so output block An again; so the end result is:
Block A
Block B
Block A
I wonder if everyone understands it.
To learn the trilogy, you can use javap-v to take a look at the compiled class file, which will make the process clearer.
You can also use idea's debug to see the difference between cinit and init.
At this point, I believe you have a deeper understanding of "java-related problem analysis". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
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.