Lectern

Search

Search IconIcon to open search

Encapsulation

Last updated Nov 7, 2022

The process of enclosing certain information. In the context of object-oriented programming, encapsulation refers to hiding irrelevant data (e.g., variables and methods) outside of a class.

# Access specifiers

Many OOP-based languages utilise access specifiers to implement encapsulation in code. The following are some examples of certain access specifiers used:

Access specifierVisible to objects of other classes within the namespaceVisible to objects of child classes within the namespaceVisible to objects of other classes outside the namespaceVisible to objects of child classes outside the namespace
publicYesYesYesYes
privateNoNoNoNo
protectedNoYesNoYes
internalYesNoNoNo
protected internalYesYesNoNo