When does the Constructor gets called in java?

前端 未结 10 1411
[愿得一人]
[愿得一人] 2020-12-16 02:14

When does the Constructor get called?

  1. Before object creation.
  2. During object creation.
  3. After object creation.
10条回答
  •  甜味超标
    2020-12-16 03:17

    basically constructors are called to initialize the values of the instance variables except the case for default constructors. However, this initialization of the instance variables are done in 4 steps (as applicable):

    1. variables are initialized with default values (ints with 0, chars with u\0000 etc.)
    2. variables are initialized with explicit initialization values
    3. initialized with static blocks
    4. constructors are called

提交回复
热议问题