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

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
oop - Difference between abstraction and encapsulation? - Stack Overflow
What is the precise difference between encapsulation and abstraction? More on stackoverflow.com
🌐 stackoverflow.com
java - Encapsulation vs Abstraction? - Stack Overflow
Here are the brief definitions of encapsulation and abstraction. ... The process of abstraction in Java is used to hide certain details and only show the essential features of the object. In other words, it deals with the outside view of an object (interface). The only good example i see for this across different ... More on stackoverflow.com
🌐 stackoverflow.com
Can anyone tell me difference between Encapsulation and Abstraction?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends. More on sololearn.com
🌐 sololearn.com
8
1
🌐
Board Infinity
boardinfinity.com › blog › abstraction-encapsulation
Abstraction Vs Encapsulation in Java
July 7, 2023 - Encapsulation wraps code and data for unnecessary information, while Abstraction presents only useful data.
🌐
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 hides implementation details, exposing only functionality, while encapsulation bundles data and methods, restricting access to protect data integrity.
🌐
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.
🌐
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....
🌐
How to do in Java
howtodoinjava.com › home › java object oriented programming › difference between encapsulation and abstraction in java
Difference Between Encapsulation and Abstraction in Java
2 weeks ago - The difference between encapsulation and abstraction in Java is that abstraction decides which operations a type offers to its callers, while encapsulation hides the type’s fields and enforces its rules behind those operations.
Find elsewhere
🌐
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....
🌐
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. Understanding their difference and implementation in Java, C++, C#, and Python will ...
🌐
Guru99
guru99.com › home › software engineering › difference between abstraction and encapsulation
Difference Between Abstraction and Encapsulation
August 6, 2026 - Abstraction shows only useful data by providing the most necessary details, whereas Encapsulation wraps code and data for necessary information.
🌐
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
🌐
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
🌐
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 - Abstraction: Makes updates easier by separating the “what” from the “how.” · Encapsulation: Ensures changes to internal data structures won’t break the rest of the code.
🌐
Java67
java67.com › 2012 › 08 › difference-between-abstraction-and-encapsulation-java-oops.html
Difference between Abstraction and Encapsulation in Java and Object Oriented Programming? [Answer] | Java67
One example of Encapsulation in Java is private methods; clients don't care about it, You can change, amend or even remove that method if that method is not encapsulated and it was public all your clients would have been affected. Apart from this main difference in behavior, I mean Abstraction hides details for simplification while Encapsulation hides details for making it easier to change, we will see a couple of more differences between Abstraction and Encapsulation in Java.
🌐
Dinesh on Java
dineshonjava.com › home › difference between abstraction vs encapsulation in java
Difference between Abstraction vs Encapsulation in Java - Dinesh on Java
January 1, 2018 - Abstraction means to show What part of functionality while Encapsulation means to hide the How part of the functionality. ... Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies.
🌐
Hero Vired
herovired.com › learning-hub › blogs › difference-between-abstraction-and-encapsulation
Difference between Abstraction and Encapsulation in Java
June 24, 2024 - The major difference between abstraction and encapsulation in Java is that encapsulation is used for the internal wrapping of the codes on the other hand abstraction is used for making the user-end less complex which is free from unwanted codes.
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.

Top answer
1 of 13
131

Abstraction is the concept of describing something in simpler terms, i.e abstracting away the details, in order to focus on what is important (This is also seen in abstract art, for example, where the artist focuses on the building blocks of images, such as colour or shapes). The same idea translates to OOP by using an inheritance hierarchy, where more abstract concepts are at the top and more concrete ideas, at the bottom, build upon their abstractions. At its most abstract level there is no implementation details at all and perhaps very few commonalities, which are added as the abstraction decreases.

As an example, at the top might be an interface with a single method, then the next level, provides several abstract classes, which may or may not fill in some of the details about the top level, but branches by adding their own abstract methods, then for each of these abstract classes are concrete classes providing implementations of all the remaining methods.

Encapsulation is a technique. It may or may not be for aiding in abstraction, but it is certainly about information hiding and/or organisation. It demands data and functions be grouped in some way - of course good OOP practice demands that they should be grouped by abstraction. However, there are other uses which just aid in maintainability etc.

2 of 13
104

Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly. So the class abstracts away the implementation details related to its state.

Abstraction is a more generic term, it can also be achieved by (amongst others) subclassing. For example, the interface List in the standard library is an abstraction for a sequence of items, indexed by their position, concrete examples of a List are an ArrayList or a LinkedList. Code that interacts with a List abstracts over the detail of which kind of a list it is using.

Abstraction is often not possible without hiding underlying state by encapsulation - if a class exposes its internal state, it can't change its inner workings, and thus cannot be abstracted.

🌐
YouTube
youtube.com › watch
Abstraction and Encapsulation Explained | Core Java Tutorial | Ashok IT - YouTube
🧠 Abstraction vs Encapsulation in Java – Explained Clearly with ExamplesUnderstanding Abstraction and Encapsulation is essential to master Java OOPS concept...
Published: February 13, 2026