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

java - Encapsulation vs Abstraction? - Stack Overflow
Here are the brief definitions of encapsulation and abstraction. Abstraction: The process of abstraction in Java is used to hide certain details and only show the essential features of the obj... More on stackoverflow.com
🌐 stackoverflow.com
oop - Difference between abstraction and encapsulation? - Stack Overflow
When we say encapsulation, emphasis should be on grouping or packaging or bundling related data and behavior together. Data Abstraction on the other hand is concept of generalizing so that the underneath complex logic is not exposed to the user. In Java this is achieved by using interfaces ... 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
Is there a difference between encapsulation & abstraction vs. data encapsulation & data abstraction?

Without any context and in relation to OO programming I'd say they're the same thing.

Also in your notes you seem to confusing the "how" with the "what" a lot. For example under "What is the Difference Between Abstraction & Encapsulation in Java?"

First, Abstraction is implemented using interface and abstract class, while Encapsulation is implemented using private and protected access modifier.

This is how you implement it but not what abstraction and encapsulation are.

You should also just separate the terms and not toss them on the same page. They are two very different concepts that really aren't related. Abstraction is about behaviour, encapsulation about information.

More on reddit.com
🌐 r/javahelp
6
2
October 19, 2016
🌐
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.
🌐
Board Infinity
boardinfinity.com › blog › abstraction-encapsulation
Abstraction Vs Encapsulation in Java
July 7, 2023 - Abstraction addresses design problems, while Encapsulation addresses implementation problems. Abstraction hides unnecessary details in code, while Encapsulation makes it easier for developers to organize the entire program.
🌐
Alma Better
almabetter.com › bytes › articles › difference-between-abstraction-and-encapsulation
Difference Between Abstraction and Encapsulation 2025
March 16, 2025 - However, abstraction focuses on hiding complexity, while encapsulation focuses on protecting data. Yes, 100% abstraction is achieved using interfaces in Java, where all methods are abstract.
🌐
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
4) Abstraction focus on outer lookout e.g. moving of vehicle while Encapsulation focuses on internal working or inner lookout e.g. how exactly the vehicle moves. 5) In Java, Abstraction is supported using the interface and abstract class while ...
🌐
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.
Find elsewhere
🌐
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 abstraction in Java is an interface while Encapsulation means hiding details of implementation from the outside world so that when things change nobody gets affected.
🌐
Guru99
guru99.com › home › software engineering › difference between abstraction and encapsulation
Difference Between Abstraction and Encapsulation
August 6, 2026 - Comparing Encapsulation vs Abstraction, Abstraction solves problems at the design level while Encapsulation solves problems at the implementation level. Abstraction hides the irrelevant details found in the code, whereas Encapsulation helps ...
🌐
DEV Community
dev.to › abhinowww › encapsulation-vs-abstraction-in-java-the-ultimate-guide-4ccf
Encapsulation vs. Abstraction in Java: The Ultimate Guide - DEV Community
October 18, 2024 - When learning Java or any object-oriented programming (OOP) language, two essential concepts stand out—Encapsulation and Abstraction. These concepts are key pillars of OOP that promote code reusability, security, and maintainability.
🌐
Medium
medium.com › @mukeshtripathi1997 › encapsulation-vs-abstraction-the-difference-every-java-developer-must-know-fdb01045b8c0
Encapsulation vs Abstraction — The Difference Every Java Developer Must Know | by CodeWithMukesh | Medium
March 20, 2026 - Encapsulation means hiding data using private variables Data is accessed using getter and setter methods It focuses on protecting data User cannot access data directly It controls how data is used · Abstraction means hiding internal logic User ...
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.

🌐
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....
🌐
Java Guides
javaguides.net › 2023 › 11 › encapsulation-vs-abstraction-in-java.html
Encapsulation vs Abstraction in Java
March 18, 2024 - Encapsulation is achieved using access modifiers, allowing you to control the visibility of class members. Abstraction in Java is a concept that aims to hide the complex reality while exposing only the necessary parts.
🌐
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
🌐
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.
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.

🌐
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
🌐
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 - So in very simple word I am telling you about Abstraction, it is nothing but it is one of the OOP concept which focuses on the process of hiding the unwanted details and exposing only the essential features of a particular object or concept, and Encapsulation is also one of the OOP concepts which also hides data from outside world but there are key differences between them to way of hiding data outside of world.
🌐
Hero Vired
herovired.com › learning-hub › blogs › difference-between-abstraction-and-encapsulation
Difference between Abstraction and Encapsulation in Java
June 24, 2024 - Overall, abstraction proves helpful in Java as it allows you to create more manageable and straightforward code, making the process more scalable, readable and maintainable. If you have grown some interest in cloud engineering, the best idea would be to opt for a Cloud engineering course . Encapsulation involves hiding the details of an object’s implementation, limiting access to its internal state.