Why can my instance initializer block reference a field before it is declared?

后端 未结 5 512
無奈伤痛
無奈伤痛 2021-01-18 03:19

My understanding is that you cannot reference a variable before it has been declared, and that all code (including instance initializers) that is within the body of a class,

5条回答
  •  悲&欢浪女
    2021-01-18 04:17

    The instance initialization blocs are called at the instance creation time.so it is normal that After the creation of the why object, it Works.

    The order of initialisation is: 1) static bloc 2)constructor 3)instance blocs on order of appearance

提交回复
热议问题