Encapsulation hides variables or some implementation that may be changed so often in a class to prevent outsiders access it directly. They must access it via getter and setter methods.

Abstraction is used to hide something too, but in a higher degree (class, interface). Clients who use an abstract class (or interface) do not care about what it was, they just need to know what it can do.

Answer from phnkha on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-abstraction-and-encapsulation-in-java-with-examples
Difference between Abstraction and Encapsulation in Java with Examples - GeeksforGeeks
May 4, 2026 - User only calls start() without knowing how it works internally (implementation is hidden). Encapsulation focuses on wrapping data (variables) and methods into a single unit and restricting direct access to the data.
Discussions

oop - Difference between abstraction and encapsulation? - Stack Overflow
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: More on stackoverflow.com
🌐 stackoverflow.com
oop - encapsulation vs abstraction real world example - Stack Overflow
For an example of encapsulation i can think of the interaction between a user and a mobile phone. The user does not need to know the internal working of the mobile phone to operate, so this is called More on stackoverflow.com
🌐 stackoverflow.com
Give one real time example to understand both "Abstraction" & "Encapsulation" ?
Hello Abstraction : It means showing only the relevant data and details. Rest of other details are hidden. Ex : We send data from Bluetooth but we really do not know anything about how it gets connected with other phones. Encapsulation : It means wrapping up of code and data under a single unit. More on sololearn.com
🌐 sololearn.com
3
7
Understanding Encapsulation and Abstraction real use case

encapsulation hides information from the caller, abstraction hides information from the callee.

when you encapsulate, you make sure the caller of a function knows as little about what the function does as it possibly can while still supporting reasonable use.

when you abstract, you make sure the function itself knows as little about how it's used as it possibly can while still allowing implementation of the desired behavior.

well encapsulated functions provide ergonomic interfaces. minimizing the surface area at the call sites by minimizing the info taken in and returned makes it easier to drop a call in to multiple different contexts without the slog that comes from a badly tangled interface that requires multiple loc to setup before or cleanup after a function call.

well abstracted functions provide more reliable behavior. limiting the power of a functions implementation by limiting its knowledge of its inputs or the contexts it's called in makes it safer to call in a wider variety of settings, simply because a less powerful (read knowledgable) function just has less opportunity to do surprising or unwelcome things.

abstraction is definitely not just a best practice, and there's hard math you can do to prove to yourself the concrete difference between different ways of writing the same code in more or less abstract ways, in terms of how many ways you can write it incorrectly. abstraction brings that number down in meaningful ways.

encapsulation is in my understanding a fuzzier idea. it's not inherent to computation, but emergent in specific programming models and languages. i can't think of a setting among programmers where it'd be contentious to say it has meaningful practical impact, but the most "precise" measure i can think of is roughly how many places in a code-base you'd have to change for a single desired change in behavior.

More on reddit.com
🌐 r/rails
8
14
July 5, 2019
People also ask

Is encapsulation possible without abstraction?
Yes, encapsulation can exist independently of abstraction. While the difference between abstraction and encapsulation often complement each other, encapsulation focuses on protecting data and limiting access, regardless of whether high-level functionality is exposed. For example, a class could encapsulate its data with private variables, even if it doesn’t simplify its functionality for the user. Abstraction is not required to implement data protection via encapsulation.
🌐
upgrad.com
upgrad.com › home › blog › software development › difference between abstraction and encapsulation: key to oop in 2026!
Difference Between Abstraction and Encapsulation Explained!
Do abstraction and encapsulation improve code readability?
Yes, the difference between abstraction and encapsulation contribute significantly to code readability. Abstraction simplifies the design by exposing only the necessary functionalities and hiding the complexities. Encapsulation, on the other hand, organizes data and methods effectively, making it easier to manage and maintain. Together, they help in creating clean, modular, and understandable code.
🌐
upgrad.com
upgrad.com › home › blog › software development › difference between abstraction and encapsulation: key to oop in 2026!
Difference Between Abstraction and Encapsulation Explained!
What is the main goal of encapsulation?
The primary goal of encapsulation is to protect an object’s data by restricting direct access and modification. By controlling how data is accessed through methods, encapsulation ensures that internal data is only modified in safe and intended ways. It also helps maintain object integrity and prevents unexpected changes from other parts of the program. The difference between abstraction and encapsulation works together to simplify user interaction while maintaining security and consistency.
🌐
upgrad.com
upgrad.com › home › blog › software development › difference between abstraction and encapsulation: key to oop in 2026!
Difference Between Abstraction and Encapsulation Explained!
🌐
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.
🌐
Alma Better
almabetter.com › bytes › articles › difference-between-abstraction-and-encapsulation
Difference Between Abstraction and Encapsulation 2025
March 16, 2025 - You don't need to understand how ... available to you. Encapsulation is the technique of wrapping data (variables) and methods (functions) into a single unit while restricting direct access to the data....
🌐
Baeldung
baeldung.com › home › core concepts › programming › differences between abstraction and encapsulation
Differences Between Abstraction and Encapsulation | Baeldung on Computer Science
March 18, 2024 - The VendingMachine class is an example of abstraction, as it defines the common characteristics of all vending machines without specifying the details of each individual. Moreover, the abstract class VendingMachine encapsulates the basic behavior ...
🌐
Tech Blog by Soam
soamtripathy.hashnode.dev › abstraction-vs-encapsulation
Abstraction vs Encapsulation in Python: OOP Explained
June 16, 2023 - In this example, the Animal class is an abstract class with an abstract method make_sound() and a protected attribute _name. The Dog and Cat classes inherit from the Animal class and provide their own implementations of the make_sound() method. The Zoo class encapsulates a list of animals and provides methods to add animals to the zoo and display the sounds they make.
Find elsewhere
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.

🌐
Medium
medium.com › @kamlesh90 › difference-between-abstraction-and-encapsulation-a82060eb946f
Difference between Abstraction and Encapsulation | by Kamlesh Singh | Medium
May 23, 2023 - In the example above, the “balance” field is encapsulated and made private. It can only be accessed through the “Balance” property, which provides read access but restricts write access to the class itself.
🌐
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 - While the difference between ... of whether high-level functionality is exposed. For example, a class could encapsulate its data with private variables, even if it doesn’t simplify its functionality for the ...
🌐
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 - In this example the variables are set to values passed in as arguments to the sum method. This is not a very true example - often the values would NOT be set just before being used like this, but it shows the reality of the implementation. ... Encapsulation is a method of making a complex system easier to handle for end users.
🌐
Unstop
unstop.com › home › blog › 10+ differences between abstraction vs encapsulation in java
10+ Differences Between Abstraction Vs Encapsulation In Java
December 31, 2024 - While abstraction hides the implementation details and provides a simplified view, encapsulation protects the internal data and controls access. For example, you might have an abstract class defining general functionality and then use encapsulation ...
🌐
Medium
codeint.medium.com › understanding-abstraction-and-encapsulation-the-dynamic-duo-of-object-oriented-programming-d2fd11caf315
Understanding Abstraction and Encapsulation: The Dynamic Duo of Object-Oriented Programming | by Sahil Thakar | Medium
May 15, 2024 - In this example, the Car class encapsulates the model field, making it private and providing public methods to access and modify it. The startEngine and stopEngine methods are the actual implementations of the abstract methods defined in the Vehicle interface.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › difference-between-abstraction-and-encapsulation-in-c
Difference between Abstraction and Encapsulation in C++ - GeeksforGeeks
August 7, 2025 - In the this example, we can see that abstraction has achieved by using class. The class 'Summation' holds the private members a, b and c, which are only accessible by the member functions of that class. Encapsulation: Encapsulation is the process of bundling or binding both data members and member function into a single unit called class.
🌐
YouTube
youtube.com › learnprograming byluckysir
Difference between encapsulation and abstraction in java | Real world example of encapsulation - YouTube
In this video you will know the key differences between encapsulation and abstraction and also get to know real world examples of encapsulation and abstracti...
Published: March 14, 2020
Views: 49K
🌐
Guru99
guru99.com › home › software engineering › difference between abstraction and encapsulation
Difference Between Abstraction and Encapsulation
August 6, 2026 - Encapsulation is a process of wrapping the data and the code, that operate on the data into a single entity. You can assume it as a protective wrapper that stops random access of code defined outside that wrapper. ... Helps you to simplify the representation of the domain models. Abstraction hides the irrelevant details found in the code.
🌐
TutorialsPoint
tutorialspoint.com › difference-between-abstraction-and-encapsulation
Difference Between Abstraction and Encapsulation
September 13, 2023 - Consequently, the user will have ... example, when we consider the case of a search on google, complex details such as what happens as soon as we search about a query, the protocol our web server uses are hidden....
🌐
Javatpoint
javatpoint.com › abstraction-vs-encapsulation-in-java
Abstraction vs Encapsulation in Java - Javatpoint
Abstraction vs Encapsulation in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
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 can modify it later with a better technique if you maintain the inner information confidential. Abstraction focuses on outside viewing, for example, shifting the car, while Encapsulation focuses on internal working or inner viewing.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai