Difference between Abstraction and Encapsulation.


Abstraction

  • Abstraction means hiding implementation.
  • Abstraction can be achieved by interfaces or abstract classes.
  • Abstraction focuses on the outside view of an object (i.e. the interface)
  • TV Remote is the real world example of abstraction where we know little bit how to operate it. but does not know how they are implemented internally.

Encapsulation

  • Encapsulation means hiding the important features of a class which is not been needed to be exposed outside of a class and exposing only necessary things of a class.
  • Encapsulation can be achieved by Access modifiers (Public, Private, Protected).
  • Encapsulation focuses on the inside view of an object where it is actually implemented(i.e the class).
  • TV contains multiple things inside it – Color tube, connections of Speaker, Channel mechanism. is the real time example of encapsulation where these things does not need to be exposed outside.