Java static final field initialization order

后端 未结 4 737
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 16:51

I tried to understand the behavior of initialization order when static fields are initialized with a reference to the same enclosing class object.

public          


        
4条回答
  •  抹茶落季
    2020-12-03 17:20

    static final a=5 It is final so it initialize first, before other static members or methods.

    In first scenario main() method get executed first and it initializea to its default value 0.

提交回复
热议问题