JAVA initialization blocks

后端 未结 6 1784
谎友^
谎友^ 2021-01-21 18:03

As some sources say, the Java instance initialization blocks are executed whenever instance is created or right before constructor. But imagine this case:

public         


        
6条回答
  •  灰色年华
    2021-01-21 18:25

    The last statement is incorrect. Main() is executed after Foo(), because a class constructor is executed after its super constructor has finished. For more details see this part of the spec, which deals with implicit and explicit super constructor calls.

提交回复
热议问题