Default constructor does not initialize the instance members of the class?

前端 未结 7 2463
清酒与你
清酒与你 2021-02-13 03:05

I encountered a question that asks \"Which of the following are true about the \"default\" constructor?\"

and an option \"It initializes the instance members of the cla

7条回答
  •  名媛妹妹
    2021-02-13 03:37

    Whenever we are executing a java class, first Static Control Flow will be executed. In the Static Control Flow if we are creating an object then the following steps will be executed(in the mentioned order) as a part of Inatance Control Flow:

    1. Identification of instance members(instance variable and instance blocks) from top to bottom.
    2. Execution of instance variable assignments and instance blocks.
    3. Execution of constructor.

    So, in your above code the instance variable "name" is already assigned to null(default value for reference types) even before the constuctor is executed.

提交回复
热议问题