Execution sequence of code segments in JAVA

Source: Internet
Author: User

I remember that at the time of my graduation, I was most afraid of studying JAVA. I have never done anything wrong with this JAVA question. I finally reviewed this page today. After reading it for a long time, I had to remember what I learned.

1. execution sequence of static code segments

The execution result is as follows:

Cup (1)
Cup (2)
Cups ()
Cups ()
Inside main ()
F (99)

Ii. execution sequence of non-static code segments


The execution result is as follows:
Inside main ()
Mug (1)
Mug (2)
C1 & c2 initialized
Mugs ()
Mug (1)
Mug (2)
C1 & c2 initialized
Mugs ()

Conclusion: There is a lot of knowledge involved here, including code blocks, anonymous internal classes, and static initialization. I feel quite clear when using such a big example.
It should be mentioned that the initialization of static variables, methods, and code blocks is only once, that is, the initialization is run when the class is called for the first time. No matter how many times the class will be new, initialization will not be run.
Close! Next, let's look at the new concept ~

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.