top button
Flag Notify
Site Registration

What is the difference between abstraction and encapsulation?

+1 vote
602 views
What is the difference between abstraction and encapsulation?
posted Sep 4, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Encapsulation is hiding the details of the implementation of an object so that there are no dependancies on the particular implementation. Abstraction represent taking out the behavior from How exactly its implemented, one example of abstraction in Java is interface.

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 were public all your clients would have been affected.

I am trying to figure out some more difference hope will it work:

1) First difference between Abstraction and Encapsulation is that, Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier.

2) Encapsulation is also called data hiding.

3) Design principles "programming for interface than implementation" is based on abstraction and "encapsulate whatever changes" is based upon Encapsulation.

answer Sep 4, 2014 by Amit Kumar Pandey
Encapsulation is called data binding whereas abstraction is called data hiding
0 votes

Data abstraction: representation of the without including background detail.
Take example of car end user(car driver) actually don't know how actual gear box work, how horn blow when he/she press the button means he/she don't know how electricity is passed in this case, what is 4stroke engine or 2 stroke engine and in that how piston is work in 4 strokes and 2 strokes. Means driver don't know how its implementation but still driver uses this functionality is called data abstraction.

Encapsulation: Wrapping up of data into a single unit is called Encapsulation. Like in the above example car is called encapsulation as it contains all element.

answer Sep 4, 2014 by Salil Agrawal
...