Encapsulation is one of the fundamental concepts of object-oriented programming (OOP). It refers to the bundling of data and methods inside a class, thereby controlling access to the data and preventing unwanted changes from the outside. Encapsulation enables better modularity and higher data security within programs.
| Accessibility | Description |
|---|---|
public |
Properties or methods marked as public are accessible both inside and outside the class. |
protected |
Properties or methods marked as protected are accessible inside the class and its subclasses, but not from the outside. |
private |
Properties or methods marked as private are accessible only within the class where they are defined. |