What is the scope of variables declared inside a static block in java?

前端 未结 4 2024
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 03:36

Are variables declared inside a static block accessible anywhere else? What \"kind\" of member are they(ie., are they static member, too?)

4条回答
  •  旧时难觅i
    2020-12-14 03:53

    Generally programmers don't need to declare any variables inside static blocks, usually this is only for ensuring initialization of static variables for use by all instances of class (depending on scope of static variable).

    Variables declared inside a static block will be local to that block just like methods and constructors variables.

    JDK Docs

提交回复
热议问题