In what order do static/instance initializer blocks in Java run?

前端 未结 8 1659
心在旅途
心在旅途 2020-11-22 17:01

Say a project contains several classes, each of which has a static initializer block. In what order do those blocks run? I know that within a class, such blocks are run in

8条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 17:46

    The static initializer for a class gets run when the class is first accessed, either to create an instance, or to access a static method or field.

    So, for multiple classes, this totally depends on the code that's run to cause those classes to get loaded.

提交回复
热议问题