Static Block in Java [duplicate]

2018-12-31 05:36发布

I was looking over some code the other day and I came across:

static {
    ...
}

Coming from C++, I had no idea why that was there. Its not an error because the code compiled fine. What is this "static" block of code?

标签: java static
7条回答
旧人旧事旧时光
2楼-- · 2018-12-31 06:27

A static block executes once in the life cycle of any program, another property of static block is that it executes before the main method.

查看更多
登录 后发表回答