Explain Encapsulation with an example.
January 11, 2025
Encapsulation restricts direct access to class members by using private modifiers and allows controlled access via public getter and setter methods.
Example:
class Person {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}