OOPs Programming Technology 

Difference between Abstraction and Encapsulation in Java

Difference between Abstraction and Encapsulation

Abstraction V/s Encapsulation

1. Abstraction solves the problem in the design level.

1. Encapsulation solves the problem in the implementation level.

2. Abstraction is used for hiding the unwanted data and giving relevant data.

2. Encapsulation means hiding the code and data into a single unit to protect the data from outside world.

3. Abstraction lets you focus on what the object does instead of how it does it

3. Encapsulation means hiding the internal details or mechanics of how an object does something.

4. Abstraction- Outer layout, used in terms of design.
For Example:-
Outer Look of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.

4. Encapsulation- Inner layout, used in terms of implementation.
For Example:- Inner Implementation detail of a Mobile Phone, how keypad button and Display Screen are connect with each other using circuits.


The easier way to understand Abstraction and encapsulation is as follows:-
Real World Example:-

Take an example of Mobile Phone to Understand Abstraction and Encapsulation:-

You have a laptop, you can power on and off using power buttons. Even you don’t know how these are working internally. This is called Abstraction. You have the only information that is needed to start this laptop. But not its internal working of laptop.

But how the laptop internally working?, how power button is connected with internal circuit? is called Encapsulation.


“Encapsulation – Keeping data and methods that accesses that data into a single unit”

“Abstraction – Just giving the abstract information about what it can do without specifying the back ground details” and keep the instance variables private or protected.”

Related posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.