Wednesday, July 10, 2013

What is Encapsulation in Java ?

Encapsulation is basically a way of doing abstraction.It is wrapping up of data into meaning full entity.
Most of the time people get confuse about abstraction and encapsulation,the words seems to have same meaning,but that's totally wrong.Now we should get back to the topic.

In simple word abstraction is hiding details that are not useful to the user.For example:
A user who goes to purchase a car ,he is interested in its functionality of gear ,brake and handle,he has no concern about how they internally work,that's why only the brakes are shown and not his lower portion.
This is abstraction,but to hide the brake's lower portion ,there was a need of proper wrapping of its components,here the encapsulation plays its part.Both the words are tightly coupled,but pose a different work.

No comments:

Post a Comment