Why final keyword is necessary for immutable class?

后端 未结 7 1226
陌清茗
陌清茗 2020-12-08 01:17

Could you please clarify that why final keyword is required before class when we are making it an immutable one. I mean, if we declare all of it\'s attr

7条回答
  •  情歌与酒
    2020-12-08 02:10

    'final' as the keyword's name suggest means that the attribute to which final keyword is attached can't be changed(in terms of value) in other words it behaves like a constant.

    As per your question if all members of the class is made private and final but the class is not made final then the same class can be inherited but the super class member are immutable as final keyword is attached to them.

提交回复
热议问题