Most answers here focus on OOP but encapsulation begins much earlier:

  • Every function is an encapsulation; in pseudocode:

    point x = { 1, 4 }
    point y = { 23, 42 }
    
    numeric d = distance(x, y)
    

    Here, distance encapsulates the calculation of the (Euclidean) distance between two points in a plane: it hides implementation details. This is encapsulation, pure and simple.

  • Abstraction is the process of generalisation: taking a concrete implementation and making it applicable to different, albeit somewhat related, types of data. The classical example of abstraction is C’s qsort function to sort data:

    The thing about qsort is that it doesn't care about the data it sorts — in fact, it doesn’t know what data it sorts. Rather, its input type is a typeless pointer (void*) which is just C’s way of saying “I don't care about the type of data” (this is also called type erasure). The important point is that the implementation of qsort always stays the same, regardless of data type. The only thing that has to change is the compare function, which differs from data type to data type. qsort therefore expects the user to provide said compare function as a function argument.

Encapsulation and abstraction go hand in hand so much so that you could make the point that they are truly inseparable. For practical purposes, this is probably true; that said, here’s an encapsulation that’s not much of an abstraction:

class point {
    numeric x
    numeric y
}

We encapsulate the point’s coordinate, but we don’t materially abstract them away, beyond grouping them logically.

And here’s an example of abstraction that’s not encapsulation:

T pi<T> = 3.1415926535

This is a generic variable pi with a given value (π), and the declaration doesn’t care about the exact type of the variable. Admittedly, I’d be hard-pressed to find something like this in real code: abstraction virtually always uses encapsulation. However, the above does actually exist in C++(14), via variable templates (= generic templates for variables); with a slightly more complex syntax, e.g.:

template <typename T> constexpr T pi = T{3.1415926535};
Answer from Konrad Rudolph on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › difference-between-abstraction-and-encapsulation-in-c
Difference between Abstraction and Encapsulation in C++ - GeeksforGeeks
August 7, 2025 - The class 'Summation' holds the ... of that class. Encapsulation: Encapsulation is the process of bundling or binding both data members and member function into a single unit called class....
🌐
Medium
medium.com › @lokeshbihani99 › deep-dive-into-abstraction-and-encapsulation-in-c-part-3-271d86d5cfbb
Deep Dive into Abstraction and Encapsulation in C++(Part 3) | by Lokesh Bihani | Medium
April 18, 2024 - It also simplifies debugging and maintenance because the access to the data members is localized using encapsulation. Abstraction hides complex implementation details and exposes only the necessary features to the user.
Discussions

oop - Difference between abstraction and encapsulation? - Stack Overflow
What is the precise difference between encapsulation and abstraction? ... check my answer here. You will get a different view on these concepts stackoverflow.com/a/65543358/12894468 ... Save this answer. ... Show activity on this post. Most answers here focus on OOP but encapsulation begins much earlier: Every function is an encapsulation; in ... More on stackoverflow.com
🌐 stackoverflow.com
Difference between abstraction and encapsulation?
I think abstraction is a more generic idea. To abstract is basically to produce a model of something that you want someone to use. For example, a road map is an abstraction for someone that only cares about roads. It doesn't try to capture, say, shops, terrain, how many lanes of traffic there is, etc. Encapsulation is more about hiding implementation details from you and to me, it's a form of abstraction. A real world example might be any electronic device you have, say, a TV remote control. There are buttons to increase the volume, decrease, change channels, etc. Most likely, these just produce infrared signals picked up by your television and the television understands what those signals mean. Maybe a better example is a car with a steering wheel, accelerator, and brakes. This is an abstraction, and the implementation is hidden away in the engine, etc. Indeed, it used to be the case that when you pressed the accelerator, it had a correlation with how much gas was used, but these days, the accelerator is read monitored by a computer, and the computer computes the most efficient way to provide the gas that lets you accelerate, but it can make better adjustments than a direct correlation to the amount of gas used. And, the same abstraction can be used for electric cars that don't use gas at all, yet, you can still have a steering wheel, accelerator, and brakes. More on reddit.com
🌐 r/learnprogramming
8
10
October 23, 2019
Data Encapsulation vs Abstraction
When in doubt, consult the godfather of C++. http://www.stroustrup.com/glossary.html Abstraction is hiding implementation details, and encapsulation is enforcement of abstraction. More on reddit.com
🌐 r/cpp_questions
6
4
April 29, 2017
Encapsulation vs Abstraction

Encapsulation is a type of abstraction. It allows you to change how your data is represented internally without affecting the interface used to manipulate the object. For example if you had a class representing a bank account that was storing the balance as a floating point number internally, you might want to change that to use an integer for the whole part and a separate integer for the fractional part, to avoid the many pitfalls of floating point types. You can do that without affecting code using the object with encapsulation.

There are other abstractions you can use as well. For example a class hierarchy for animals that all have a moveTo() method inherited from the parent class but implemented differently for creatures that fly vs. walk vs. swim.

More on reddit.com
🌐 r/learnprogramming
2
2
November 16, 2022
🌐
C# Corner
c-sharpcorner.com › home › technologies › c# › abstraction and encapsulation
Abstraction and Encapsulation
June 13, 2012 - ... Encapsulation can be implemented with different levels of access to object data. Example, private method cannot be visible to out side of class. Abstraction allows making relevant information visible outside and encapsulation enables you to implement the desired level of abstraction.
🌐
LearnTube
learntube.ai › home › digital marketing › encapsulation and abstraction in c++ programming
Encapsulation and Abstraction in C++ Programming - Learn Tube
March 11, 2023 - Encapsulation and Inheritance: Encapsulation and inheritance work together to provide a powerful mechanism for creating complex, hierarchical data structures. Inheritance allows you to create a new class that is based on an existing class, and ...
Top answer
1 of 16
330

Most answers here focus on OOP but encapsulation begins much earlier:

  • Every function is an encapsulation; in pseudocode:

    point x = { 1, 4 }
    point y = { 23, 42 }
    
    numeric d = distance(x, y)
    

    Here, distance encapsulates the calculation of the (Euclidean) distance between two points in a plane: it hides implementation details. This is encapsulation, pure and simple.

  • Abstraction is the process of generalisation: taking a concrete implementation and making it applicable to different, albeit somewhat related, types of data. The classical example of abstraction is C’s qsort function to sort data:

    The thing about qsort is that it doesn't care about the data it sorts — in fact, it doesn’t know what data it sorts. Rather, its input type is a typeless pointer (void*) which is just C’s way of saying “I don't care about the type of data” (this is also called type erasure). The important point is that the implementation of qsort always stays the same, regardless of data type. The only thing that has to change is the compare function, which differs from data type to data type. qsort therefore expects the user to provide said compare function as a function argument.

Encapsulation and abstraction go hand in hand so much so that you could make the point that they are truly inseparable. For practical purposes, this is probably true; that said, here’s an encapsulation that’s not much of an abstraction:

class point {
    numeric x
    numeric y
}

We encapsulate the point’s coordinate, but we don’t materially abstract them away, beyond grouping them logically.

And here’s an example of abstraction that’s not encapsulation:

T pi<T> = 3.1415926535

This is a generic variable pi with a given value (π), and the declaration doesn’t care about the exact type of the variable. Admittedly, I’d be hard-pressed to find something like this in real code: abstraction virtually always uses encapsulation. However, the above does actually exist in C++(14), via variable templates (= generic templates for variables); with a slightly more complex syntax, e.g.:

template <typename T> constexpr T pi = T{3.1415926535};
2 of 16
251

Many answers and their examples are misleading.

Encapsulation is the packing of "data" and "functions operating on that data" into a single component and restricting the access to some of the object's components.
Encapsulation means that the internal representation of an object is generally hidden from view outside of the object's definition.

Abstraction is a mechanism which represent the essential features without including implementation details.

Encapsulation:-- Information hiding.
Abstraction:-- Implementation hiding.

Example (in C++):

class foo{
    private:
        int a, b;
    public:
        foo(int x=0, int y=0): a(x), b(y) {}

        int add(){    
            return a+b;   
        } 
}  

Internal representation of any object of foo class is hidden outside of this class. --> Encapsulation.
Any accessible member (data/function) of an object of foo is restricted and can only be accessed by that object only.

foo foo_obj(3, 4);
int sum = foo_obj.add();

Implementation of method add is hidden. --> Abstraction.

🌐
Reddit
reddit.com › r/learnprogramming › difference between abstraction and encapsulation?
r/learnprogramming on Reddit: Difference between abstraction and encapsulation?
October 23, 2019 -

They both have extremely similar definitions. I keep getting conflicting information from the internet that varies from "encapsulation is a subset of abstraction" to "encapsulation is a completely different thing than abstraction".

Top answer
1 of 5
9
I think abstraction is a more generic idea. To abstract is basically to produce a model of something that you want someone to use. For example, a road map is an abstraction for someone that only cares about roads. It doesn't try to capture, say, shops, terrain, how many lanes of traffic there is, etc. Encapsulation is more about hiding implementation details from you and to me, it's a form of abstraction. A real world example might be any electronic device you have, say, a TV remote control. There are buttons to increase the volume, decrease, change channels, etc. Most likely, these just produce infrared signals picked up by your television and the television understands what those signals mean. Maybe a better example is a car with a steering wheel, accelerator, and brakes. This is an abstraction, and the implementation is hidden away in the engine, etc. Indeed, it used to be the case that when you pressed the accelerator, it had a correlation with how much gas was used, but these days, the accelerator is read monitored by a computer, and the computer computes the most efficient way to provide the gas that lets you accelerate, but it can make better adjustments than a direct correlation to the amount of gas used. And, the same abstraction can be used for electric cars that don't use gas at all, yet, you can still have a steering wheel, accelerator, and brakes.
2 of 5
3
There are definitely similarities. Encapsulation is essentially saying that we're going to take something and hide it away in a container. Maybe the container provides some way of interacting with the what's in it, but you can't access what's in it directly. This is like private variables with public getters/setters, or APIs in general. Abstraction is saying that we have a specification, and we want to have things that adhere to that specification. It doesn't matter how they're implemented - that's abstracted away. We care about that it behaves the way we want. Thus we can change the implementation without changing the code that uses the abstraction. Now, we see some significant links here. Encapsulation is a way to deal with abstractions - you use the abstraction as an encapsulation of the implementation. You could perhaps contrive of some scenarios where you can have one without the other, but in practice they are inseparable.
🌐
Engineering LibreTexts
eng.libretexts.org › campus bookshelves › delta college › c++ data structures › 6: abstraction / encapsulation
A.1: Difference between Abstraction and Encapsulation in C++ - Engineering LibreTexts
September 25, 2020 - The user need not worry about internal details and complexities of the system. Encapsulation is a process of wrapping the data and the code, that operate on the data into a single entity.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › difference-between-abstraction-and-encapsulation
Difference Between Abstraction and Encapsulation
September 13, 2023 - Abstraction is a process of hiding the implementation details of a system from the user, and only the functional details will be available to the user end. On the other hand, Encapsulation is a method of wrapping up the data and code acting ...
🌐
Medium
rajndev.medium.com › abstraction-vs-encapsulation-in-c-clearly-explained-3c1c15b7cfb6
Abstraction vs. Encapsulation in C - Raj Narayanan - Medium
April 9, 2022 - The code snippet below illustrates Encapsulation with a class modeling an ATM Machine. Notice that it contains only relevant attributes and methods and that sensitive attributes like totalCashInAtm is hidden from outside access with private access modifiers: Abstraction in OOP, on the other hand, is the process of reducing the complexities of a class to a few publicly accessible user interfaces.
🌐
Sololearn
sololearn.com › en › Discuss › 3318626 › tell-me-the-difference-between-abstraction-encapsulation-in-c
Tell me the difference between Abstraction & encapsulation in c++ | Sololearn: Learn to code for FREE!
Abstraction is nothing but which only shows essential elements and hide background details where as Encapsulation is binding of data members and member functions together. ... Why Sololearn Removed Our Saved Private Project (Codes), I Can't ...
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › difference between encapsulation and abstraction
Difference Between Encapsulation and Abstraction - Shiksha Online
December 27, 2023 - 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.
🌐
Scribd
scribd.com › document › 509678013 › Difference-Between-Abstraction-and-Encapsulation-in-C
Abstraction vs Encapsulation in C++ | PDF
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Medium
medium.com › @bindubc › abstraction-versus-encapsulation-versus-information-hiding-d1c70fd47c37
Abstraction versus Encapsulation versus Information Hiding | by Bindu C | Medium
March 4, 2025 - encapsulation (achieved through information hiding) = the object internally, ... Its nothing but wrapping the data and method into single unit or Group To Prevent any accidental change, this single unit imposes certain set of restriction rules on accessing the variable and methods which can be accessed by object’s method.
🌐
YouTube
youtube.com › scholarhat
Abstraction and Encapsulation In C++ - YouTube
In this video, we'll be covering the concepts of abstraction and encapsulation in C++. We'll be using the example of a simple class to explain these concepts...
Published: February 25, 2023
Views: 650
🌐
Upgrad
upgrad.com › home › blog › software development › difference between abstraction and encapsulation: key to oop in 2026!
Difference Between Abstraction and Encapsulation Explained!
July 7, 2026 - The difference between abstraction ... Abstraction hides internal details, exposing only necessary functionality, while encapsulation restricts direct data access and ensures controlled interaction via methods...
🌐
Scribd
scribd.com › presentation › 472538481 › Abstraction-Encapsulation-in-C
Abstraction vs Encapsulation in C++ | PDF | Class (Computer Programming) | Abstraction (Computer Science)
- Encapsulation is achieved through access specifiers like public, private, protected. Data members are declared as private and member functions as public to achieve encapsulation.
🌐
Medium
medium.com › @kamlesh90 › difference-between-abstraction-and-encapsulation-a82060eb946f
Difference between Abstraction and Encapsulation | by Kamlesh Singh | Medium
May 23, 2023 - To summarize, abstraction focuses on defining the essential behavior of an object while hiding the implementation details, whereas encapsulation focuses on bundling data and methods together within a class, providing controlled access to the ...
🌐
Quora
quora.com › What-is-the-difference-between-encapsulation-and-abstraction-As-I-understood-it-both-of-them-are-about-not-needing-to-know-how-a-job-is-done-but-what-is-the-difference-between-the-two
What is the difference between encapsulation and abstraction? As I understood it, both of them are about not needing to know how a job is done, but what is the difference between the two? - Quora
Answer (1 of 3): Encapsulation The main point of encapsulation is that you hide how some data is actually stored. For example, we have a database of LOTS AND LOTS of people. Each has a set of properties, such as first name, last name, date of birth, address, etc. Now, we can of course just stor...