Encapsulation
By Tiationg Kho |
Encapsulation
- Protect and control access to data
- Access Modifiers
- Java provides several access modifiers to set access levels for classes, variables, and methods
public
- Can be accessed from any other class
protected
- Can be accessed from its own package or subclasses
- default (no keyword required)
- Can be accessed from its own package
private
- Can be accessed only from its own class
- Getter and Setter Methods
- We can use
public
getter/setter methods to access/modify the private
variables