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
🌐
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 - Abstraction is the concept of object-oriented programming that "shows" only essential attributes and "hides" unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users.
🌐
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.
Discussions

java - Difference between Encapsulation and Abstraction - Stack Overflow
I had an interview today. I had a question from OOP, about the difference between Encapsulation & Abstraction? I replied to my knowledge that Encapsulation is basically binding data members & More on stackoverflow.com
🌐 stackoverflow.com
I don't understand abstraction, encapsulation and interfaces.
Encapsulation is a principle. Using getters/setters is a way of implementing that principle. Keeping functions that no one needs to mess with private is part of it too. The main benefit is that in the future if you change something as long as public names stay the same and do the same things conceptually you can reorganize the internals and not break any code that is using it. That does mean that you should take care when you define your public methods and such, because changing them later on down the line involves potentially breaking anything that uses them. As for interfaces an example is probably best. Look at the Incomparable interface from C#. Any class can implement it. Say you have some class that contains say a creation date, and you want it to be sorted by date. If you implement IComparable now you can just put it in a List and call sort and it works. But there's no way the guys who wrote List<> could have possibly known that ahead of time. Same if you write your own class like say a custom binary tree. You can set it up so that it works with anything that Implements IComparable without needing to care if you are sorting based on name, date, whatever internal private thin it makes the most sense to sort the things by. Interfaces let you expose smaller subsections of your classes public members at a time. That way as long as you don't change the Interface you can rename other public methods without breaking anything that only interacts with your class via the interface. That again does mean that you should really make sure when crafting the interface that you won't be likely to need to change it in the future. As for your last thing, I think you are just referring to libraries. They can come in static libraries that get linked in with 3rd party code at compile time, or dynamic/shared that come as a separate file and get loaded by 3rd party code when it is run. More on reddit.com
🌐 r/learnprogramming
18
10
June 25, 2022
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
ELI5: Abstraction vs Encapsulation?
Can anyone provide a simple and clear explanation as to the differences between Abstraction and Encapsulation? More on reddit.com
🌐 r/javascript
7
8
November 12, 2015
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.

🌐
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.
🌐
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.
🌐
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....
🌐
Quora
quora.com › What-is-the-difference-between-abstraction-and-encapsulation-2
What is the difference between abstraction and encapsulation? - Quora
Answer (1 of 48): I will try to explain both encapsulation and abstraction by starting with a code that doesn't have any. Imagine you have this in C: [code]struct Rectangle { int left; int top; int width; int height; int color; }; struct Circle { int centerX; int centerY; int r...
Find elsewhere
🌐
Alma Better
almabetter.com › bytes › articles › difference-between-abstraction-and-encapsulation
Difference Between Abstraction and Encapsulation 2025
March 15, 2025 - Both abstraction and encapsulation are crucial in OOP but serve different purposes. Abstraction simplifies design by hiding unnecessary details, whereas encapsulation secures data and ensures controlled access.
🌐
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 ...
🌐
LearnTube
learntube.ai › home › digital marketing › encapsulation and abstraction in c++ programming
Encapsulation and Abstraction in C++ Programming - Learn Tube
March 11, 2023 - Inheritance allows you to create a new class that is based on an existing class, and encapsulation allows you to hide the implementation details of both classes. ... Generalization: Abstraction allows you to represent a class at a higher level ...
🌐
C# Corner
c-sharpcorner.com › article › encapsulation-and-abstraction-same-or-different
Encapsulation And Abstraction, Same Or Different?
June 2, 2023 - So we can conclusively say that abstraction can be seen in a certain sense as an extension of the concept of encapsulation but from a broader perspective.
🌐
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...
🌐
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...
🌐
Medium
rajndev.medium.com › abstraction-vs-encapsulation-in-c-clearly-explained-3c1c15b7cfb6
Abstraction vs. Encapsulation in C - Raj Narayanan - Medium
April 9, 2022 - Abstraction in OOP is the process of minimally exposing only relevant information and behaviors to the user and hiding the underlying complexities by using private access modifier. On a side note, the meaning of “hiding” used in Abstraction has a subtle difference from its meaning used in Encapsulation.
🌐
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 ...
🌐
Guru99
guru99.com › home › software engineering › difference between abstraction and encapsulation
Difference Between Abstraction and Encapsulation
August 6, 2026 - Abstraction is focused mainly on what should be done, while Encapsulation is focused on how it should be done. Abstraction hides complexity by giving you a more abstract picture, while Encapsulation hides internal work so that you can change ...
🌐
Baeldung
baeldung.com › home › core concepts › programming › differences between abstraction and encapsulation
Differences Between Abstraction and Encapsulation | Baeldung on Computer Science
March 18, 2024 - So, an interface is like a contract ... implements an interface must implement all its methods. Encapsulation is a mechanism that packs data and methods into a single unit....
🌐
EDUCBA
educba.com › home › software development › software development tutorials › top differences tutorial › abstraction vs encapsulation
Abstraction vs Encapsulation | Difference Between Them
July 12, 2023 - You are the user, and you don’t want to know your motorcycle specifics or what portion has actually broken. You don’t care; you simply want your motorcycle in its original condition without worrying about the details. You told the mechanic what you wanted by separating the implementing part; this is called abstraction. The most important thing you did was fix your motorcycle instead of focusing on the particulars. Another concept of OOP encapsulation binds data and functionalities into one component while limiting access to certain components has been established.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai