Can a final variable be initialized when an object is created?

前端 未结 8 763
夕颜
夕颜 2020-12-09 10:29

how it can be possible that we can initialize the final variable of the class at the creation time of the object ?

Anybody can explain it how is it possible ? ...<

8条回答
  •  星月不相逢
    2020-12-09 10:57

    As you know instance variable is associated with class object only ,And final keyword before variable means you can't change the value of variable so variable existence is only when object is created that's why we can assign the final variable value three ways as mentioned above before creation of object(eg. by static block,when you declare) or at the time of creation of object(eg. through constructor)

提交回复
热议问题