Do objects encapsulate data so that not even other instances of the same class can access the data?

前端 未结 7 1654
梦如初夏
梦如初夏 2020-12-03 22:35

In Java,

Do objects encapsulate data so that not even other instances of the same class can access the data? Only when the keyword \"private\" is used? What are \"ac

7条回答
  •  星月不相逢
    2020-12-03 23:11

    Do objects encapsulate data so that not even other instances of the same class can access the data?

    Sure, if you are not using static members.

    Extract from this link:

    Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called static fields or class variables

提交回复
热议问题