Encapsulation is a way to achieve “information hiding” so, you don’t “need to know the internal working of the mobile phone to operate” with it. You have an interface to use the device behavior without knowing implementation details.
- You get into the car, press a button or turn a key to start the car and drive away, you don’t need to know what exactly happens behind the scene with the engine and all the mechanics to operate your car. Internal details of the starting operations are hidden from you
- Your laptop is connected to the internet, you don’t need to understand how the internet works to use it.
- In code or while writing code, Encapsulation is to hide the variables or something inside a class, preventing unauthorized parties to use. So the public methods like getter and setter access it and the other classes call these methods for accessing
Abstraction on the other side can be explained as the capability to use the same interface for different objects. Different implementations of the same interface can exist. Details are hidden by encapsulation.
A process of picking the essence of an object you really need
In other words, pick the properties you need from the object Example:
a. TV — Sound, Visuals, Power Input, Channels Input.
b. Mobile — Button/Touch screen, power button, volume button, sim port.
c. Car — Steering, Break, Clutch, Accelerator, Key Hole.
d. Human — Voice, Body, EyeSight, Hearing, Emotions.
To put it simply, ABSTRACT everything you need and ENCAPSULATE everything you don’t need.
Source — (StackOverflow)