Abstraction & Encapsulation are two important OOPs concept. Most of the IT developers are confused in Abstraction & Encapsulation. Here’s a simple & short description about these two, Which will depict clear picture.
Abstraction : Abstraction is used to hide implementation detail of methods ( behavior of a class). It can be achieved by using methods, abstract class or interface. (when we expose any API to client. Client can only see or know the functionality of an API rather than actual logic).
Encapsulation: Encapsulation is used to hide data/ information. It can be achieved by using classes, access modifiers (Public, Private, Protected & Default ). Client can’t see the properties of class until the properties are exposed through the method.
Here’s an example of Employee class with three properties.
Client even can’t see, how employee salary is being implemented. It means, abstraction is achieved.
In above example, Client can’t see properties detail of employee class. It means, encapsulation is achieved.
Note: Feel free to comment, If you have any query or concern.