Private Class Data
Control write access to class attributes
Separate data from methods that use it
Encapsulate class data initialization
Providing new type of
final
- final after constructor
Example - Hide attributes by keeping them elsewhere
In this example, we want to hide user's password variable.
User of the code does not have to know how is data internally stored in class, he uses the code as normally. But he can't access getPassword()
method anywhere.
This is simplified example, we could be hiding variables, methods or some functionality at initialization of an object.
Last updated
Was this helpful?