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
What is the precise difference between encapsulation and abstraction? More on stackoverflow.com
🌐 stackoverflow.com
What is the difference between abstraction and encapsulation?
Abstraction and encapsulation are two key concepts in object-oriented programming (OOP), but they serve different purposes. More on designgurus.io
🌐 designgurus.io
1
10
November 23, 2024
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
Reddit - The heart of the internet
Reddit is where millions of people gather for conversations about the things they care about, in over 100,000 subreddit communities. More on amp.reddit.com
🌐 r/learnprogramming
People also ask

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!
Does encapsulation ensure data integrity?
Yes, encapsulation plays a crucial role in ensuring data integrity by restricting unauthorized access to an object’s internal data. With encapsulation, you can apply specific validation checks in the getter and setter methods to ensure data is always accurate and consistent. This helps maintain the object’s internal state and prevents invalid changes. In conjunction with abstraction vs encapsulation, it ensures both security and functional reliability in software systems.
🌐
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.
🌐
Baeldung
baeldung.com › home › core concepts › programming › differences between abstraction and encapsulation
Differences Between Abstraction and Encapsulation | Baeldung on Computer Science
March 18, 2024 - Due to their similarities, these terms are often used interchangeably but mean different things. So, it’s essential to know the difference: encapsulation is about hiding information, while abstraction is about hiding implementation.
🌐
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 - Therefore we can say that, the variable a and the methods set() as well as get() have bound together that is encapsulation. There is nothing special about the method names "get()" or "set()" - there may be other methods that manipulate the variable number1...all together this is called encapsulation. Output: 10 · Difference between Abstraction and Encapsulation: Adapted from: "Difference between Abstraction and Encapsulation in C++" by MKS075, Geeks for Geeks is licensed under CC BY-SA 4.0
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.

Find elsewhere
🌐
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 ...
🌐
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 - The most significant difference between the two is that data abstraction is a method which helps to hide the unwanted data from the user, while data encapsulation is a method which helps to hide data using a single entity.
🌐
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
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 - Abstraction allows you to build a high-level structure and define clear interfaces, while encapsulation ensures that the internal workings of these structures are hidden and protected from unintended interference.
🌐
Guru99
guru99.com › home › software engineering › difference between abstraction and encapsulation
Difference Between Abstraction and Encapsulation
August 6, 2026 - Abstraction hides the irrelevant details found in the code, whereas Encapsulation helps developers to organize the entire code easily. Difference between Abstraction and Encapsulation in Java
🌐
Board Infinity
boardinfinity.com › blog › abstraction-encapsulation
Abstraction vs Encapsulation | Board Infinity
July 7, 2023 - A prime difference between abstraction and encapsulation is that abstraction hides the complexity of the code, while encapsulation hides its internal functions.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › top differences tutorial › abstraction vs encapsulation
Abstraction vs Encapsulation | Difference Between Them
July 12, 2023 - Let us discuss some of the major differences between Abstraction vs Encapsulation: The main difference between abstraction and encapsulation is that the problem is solved by Abstraction at the design level and the application level by Encapsulation.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Simplilearn
simplilearn.com › home › resources › software development › java tutorial for beginners › difference between encapsulation and abstraction explained
Difference Between Encapsulation and Abstraction Explained
July 31, 2025 - Learn the key differences in Encapsulation vs Abstraction. Encapsulation protects sensitive data, while Abstraction hides unnecessary details to reduce complexity.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
DEV Community
dev.to › saurav_dev_2022 › abstraction-vs-encapsulation-whats-the-difference-simplified-105o
Abstraction vs. Encapsulation — What’s the Difference? (Simplified) - DEV Community
April 22, 2026 - If you only remember one thing from this post, let it be this: Abstraction hides complexity (the "how"), while Encapsulation hides data (the "state"). Abstraction is about simplicity.
🌐
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.
🌐
Blogger
javarevisited.blogspot.com › 2017 › 04 › difference-between-abstraction-and-encapsulation-in-java-oop.html
Difference between Abstraction and Encapsulation in Java? OOP Question Answer
Here are some of the key differences ... Abstraction and Encapsulation is that Abstraction solves the problem at the design level while Encapsulation solves its implementation level....
🌐
Unstop
unstop.com › home › blog › 10+ differences between abstraction vs encapsulation in java
10+ Differences Between Abstraction Vs Encapsulation In Java
December 31, 2024 - Abstraction focuses on hiding the complex implementation details and exposing only the necessary functionality, whereas encapsulation is about bundling the data and methods that operate on the data within a single unit, ensuring data protection and controlled access. In this article, we'll explore the key differences between abstraction and encapsulation in Java and how they contribute to building robust software systems.