Mark As Completed Discussion

Types of Encapsulation?

Let us delve deeper and examine the three types of encapsulation:

1. Member Variable Encapsulation

A class's member variables and methods are encapsulated from outside the class. In theory, this is accomplished by concealing variables and methods within a class. A programmer cannot access or call internal variables or methods unless the code that makes up the class explicitly grants them permission.

2. Class Encapsulation

This type of encapsulation seals the class and prevents users from changing its functionality. For example, if a programmer uses a specific tool to create a class, they are not permitted to edit the source code; only the creator is permitted to change that class. Encapsulated classes are generally inaccessible to users unless they have special permissions.

3. Function Encapsulation

When a programmer calls a function, the function container "encapsulates" that function to hide its internal details. The function can only be called in the same way it was called in the first place. The outcome of calling this function will differ depending on whether or not the programmer calls any other functions during the execution of that program.