Difference Between Encapsulation and Abstraction

Difference Between Encapsulation and Abstraction

4 mins read1.8K Views Comment
Anshuman Singh
Senior Executive - Content
Updated on Dec 27, 2023 06:16 IST

The primary difference between abstraction and encapsulation is that abstraction is a design level process that focuses on hiding the complex details and implementation of the code. In contrast, encapsulation is an implementation level process that focuses on hiding the data and controlling the visibility of the code.


In this article, we will explore the difference between abstraction and encapsulation. But, before we move on to that, it would be much better to go through the list of topics listed under the Table of Contents (TOC) that we will cover in this article.

Table of contents

Difference Between Encapsulation and Abstraction

For better clarity, let's explore the difference between encapsulation and abstraction in a tabular format:

Parameter Encapsulation Abstraction
Process It is the process or method for containing information.  It is a process or method of obtaining information. 
Solving problem at During encapsulation, issues are resolved at the implementation level.  Abstractions solve problems at the design or interface level. 
Focus The focus of encapsulation is “how” it should be done. The focus of abstraction is “what” to do.
Definition It is a way of hiding data in a single entity or unit and a way of protecting information from the outside world.  Abstraction is a way of hiding unnecessary information. 
Implementation It can be implemented using access modifiers, i.e. private, protected, public.  Abstract classes and interfaces can be used to implement abstractions
Access It hides data from direct access by users (data hiding). Abstractions allow access to specific pieces of data.
All About Templates in C++
All About Templates in C++
Generic programming is an approach where generic types are used as arguments in algorithms so that they can work for various data types.
How to use For Loop in C++
How to use For Loop in C++
Loops are used to repeat the same, or similar code number of times. In this article we will discuss how to implement for loops in c++.
All About Virtual Functions in C++
All About Virtual Functions in C++
In C++, a virtual function is a member function of a class that can be overridden by derived classes. It is declared as virtual in the base class and can...read more

Learn more about OOPs in C++

Explore free C++ courses

What is Encapsulation?

Encapsulation is a way of making a complex system easier for end users to use. Users don’t have to worry about the internal details and complexities of the system. Encapsulation is the process of wrapping data and the code that processes the data into a single entity. It can be assumed to be a protective wrapper that stops accidental access to code defined outside of that wrapper. You can achieve encapsulation by declaring all variables within a class private and writing public methods within the class to set and get the values ​​of the variables.

Example of Encapsulation

In a particular project company, the various teams work like a functional team - a development team, a test team, a content team, and a project team to do other tasks. Let’s say the content team wants all the data about the development team. In this case, the data cannot be accessed directly. The content team should reach out to someone from the development team and ask them to provide the data. This is encapsulation. The data (project data + employee data) is grouped under one name, the “development team.”

Applications of Encapsulation

  • Mobile devices can perform a variety of functions, including taking pictures, sending messages, recording video/audio, accessing the Internet, etc.
  • Facebook keeps your password private to keep your account secure and prevents anyone from logging into your account.
  • It takes data from the user (amount and PIN) and displays the data in the form of icons and options. Handle requests (functions).

What is Abstraction?

Data abstraction is a property that hides unimportant entities from the user. This is the process of ignoring irrelevant details and identifying only the essential features of an object. Hide background details and highlight key data points to reduce complexity and increase efficiency. It usually only keeps the information most relevant to that particular process. Abstraction techniques focus primarily on ideas rather than actual work.

Also read: Abstract Class in C++: All You Need to Know

Example of abstraction

  • However, users don’t know how their passwords are validated on the backend to protect their accounts. This is one of many real-world cases where encapsulation is used in the industry.
  • Clicking on an icon allows the abstraction to perform a specific function. On clicking the icon, the backend process works and directs the user to the next step.

Applications of abstraction

  • Hiding bank account details from the outside world
  • Hiding a password from another person. 
  • Using smartphone features and not checking how it works.

Key Differences Between Encapsulation and Abstraction

  • Encapsulation is the practice of bundling data and methods within a single unit, like a class, and controlling their access, whereas abstraction is about hiding complex implementation details and exposing only the essential functionalities.

  • Abstraction reduces complexity by focusing on the essential features needed for a particular context, without delving into the underlying technicalities. On the other hand, encapsulation secures data and functions within a class, preventing unauthorized access and modification.

  • Encapsulation centers around how an object's data is accessed and manipulated, ensuring data integrity and privacy. Meanwhile, abstraction deals with what an object does, simplifying the representation of complex systems.


Encapsulation and abstraction are key concepts in modern programming languages like C++. These languages provide many ways for developers to implement high-level abstractions and safely extend existing systems with new functionality. While these languages have their roots in hardware design, they’re useful no matter what you’re building.

We have explored the meaning of two very important OOP concepts abstraction and encapsulation and understood their definition of them. We’ve covered examples of abstraction and encapsulation. We also explored the benefits of using his OOP concepts such as abstraction and encapsulation. Finally, we discussed the difference between abstraction and encapsulation.

About the Author
Anshuman Singh
Senior Executive - Content

Anshuman Singh is an accomplished content writer with over three years of experience specializing in cybersecurity, cloud computing, networking, and software testing. Known for his clear, concise, and informative wr... Read Full Bio