Who should load static code blocks and main functions first ???

Source: Internet
Author: User

In programming, how can we solve our problems when we encounter problems?

Start-up programming and compile a small program to easily see the desired results and answers!

Today I learned static {} static code blocks, but I don't know who should load them first with the static main () function?

So: I wrote a small piece of code:

The Code is as follows:

 

Package Stu. love. a; public class staticdemo1 {static {system. out. println ("A");}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubsystem. out. println ("B");} static {system. out. println ("C ");}}

Running result:



Conclusion: Load Static {} first!


Hands-on programming is a learning technique!


Why is static {} First loaded?

Because static {} is the initialization of the class! The variables in the class may be called in Main. Therefore, static Initialization is required first!

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.