encapsulation
5 tutorials tagged “encapsulation”.
- Access Modifiers in Javaprivate, package-private, protected and public: who can reach a class, field or method, the protected subclass rule, and the errors across packages.
- Data Hiding vs EncapsulationData hiding makes fields private; encapsulation also bundles the rules that protect them. A side-by-side example shows why hiding alone isn't enough.
- Defensive Copying in JavaProtect an object's internals from callers: copy mutable inputs in constructors and outputs in getters, with lists, arrays and dates as examples.
- Getters and Setters in JavaMethods that read and change private fields: naming rules, validation in setters, read-only fields, boolean is-getters, and safe getters for lists.
- Encapsulation in JavaKeep an object's data private and let methods guard every change. Why public fields break, how encapsulation enforces rules, and what it buys you.