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
The idea of encapsulation is to allow implementations of different units to vary freely. Although we talk of objects, for encapsulation we really mean a unit of code. In class-based languages, the unit of code is usually the [outer] class.
It also happens that binary operations (such as equals) become daft without access within the same class. So private means private to the [outer] class, not private to the same class within the same instance.
Accessor methods generally indicate bad design on anything but simple value objects (getters only). Objects should have behaviour, rather than just be a dumb collection of data. Move code that would be on the outside using getters to a method that is meaningful on the object. Hand on heart, 99% of the time getters just return a field value. There is relatively little value in making a field private if you are going to add a getter and setter.