---
title: "What is the difference between abstraction and encapsulation?"  
description: "What is the difference between abstraction and encapsulation?"  
author: "Steilla Mitchel"  
published: 2023-06-21  
updated: 2023-06-25  
canonical: https://www.mindstick.com/forum/158816/what-is-the-difference-between-abstraction-and-encapsulation  
category: "oops"  
tags: ["oops", "programming language", "abstraction"]  
reading_time: 3 minutes  

---

# What is the difference between abstraction and encapsulation?

What is the [difference between abstraction and encapsulation](https://www.mindstick.com/interview/2393/what-is-the-difference-between-abstraction-and-encapsulation)?

## Replies

### Reply by Aryan Kumar

[Abstraction and encapsulation](https://www.mindstick.com/forum/156710/differentiate-between-data-abstraction-and-encapsulation) are two important concepts in object-oriented programming (OOP). They are both ways of hiding information, but they do so in different ways.

**Abstraction** is the process of hiding implementation details from the user. This means that the user only sees the essential behavior of the object, without having to worry about how it is implemented. For example, a user of a Circle object only needs to know that they can draw the circle and calculate its area. They do not need to know how the circle is implemented, such as the fact that it is made up of a set of points.

**Encapsulation** is the process of grouping data and methods together into a single unit. This means that the data and methods are protected from outside access. For example, the Circle object might have a property called radius. This property is encapsulated, which means that the user cannot directly access it. Instead, they must use the getRadius() and setRadius() methods to access the property.

The main [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between abstraction and encapsulation is that abstraction hides implementation details, while encapsulation hides data. Abstraction is concerned with what the object does, while encapsulation is concerned with how the object does it.

Here is a table that summarizes the differences between abstraction and encapsulation:

| Feature | Abstraction | Encapsulation |
| --- | --- | --- |
| What it hides | Implementation details | Data |
| What it is concerned with | What the object does | How the object does it |
| How it is implemented | Using abstract classes and interfaces | Using access modifiers |

Here are some examples of where abstraction and encapsulation might be used:

## Abstraction:

- An abstract class might be used to define the common behavior of all shapes. This would allow the user to work with shapes without having to worry about how they are implemented.
- An interface might be used to define the common behavior of all web controllers. This would allow the user to work with web controllers without having to worry about how they are implemented.

## Encapsulation:

- A class might have a property called password. This property would be encapsulated, which would prevent the user from directly accessing it. Instead, they would have to use the getPassword() and setPassword() methods to access the property.
- A class might have a method called calculateTax(). This method would be encapsulated, which would prevent the user from directly calling it. Instead, they would have to call the calculateTax() method on an object of the class.


---

Original Source: https://www.mindstick.com/forum/158816/what-is-the-difference-between-abstraction-and-encapsulation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
