Difference between Abstraction and Encapsulation

Earlier we discussed about basics of Object oriented programming , what abstraction in OOPs is and what encapsulation means . Today let us see what differentiates abstraction from encapsulation.

  1. Abstraction is implemented through Interface and abstract classes in Java. While encapsulation is implemented by using access modifiers like private, public and protected.
  2. Encapsulation is also called data hiding. That is hiding the details from outside the world.
  3. Abstraction is based on design principal of “programming for interface than implementation” and basis of encapsulation is “encapsulate whatever changes”.
  4. Abstraction resolves the problem at the design level but the encapsulation resolves the problem at the implementation level.
  5. Abstraction hides the irrelevant details and gives relevant information. Encapsulation is encapsulating data and functions into single unit so that it can be protected from outside the world.
  6. Abstraction focuses on what the object does rather than how it does. Encapsulation hides the internal features which implement the functionality of the class.
  7. Example of abstraction is “Outer look of the mobile like the display screen on which the numbers are displays and keypads on which the digits and other character are displayed”. Example of encapsulation is inner layout of the mobile phone like how the how the keypad and its different buttons are connected with the screen.
Difference between encapsulation and abstraction wiki java oops
Difference between Abstraction and Encapsulation
Copyright © ianswer4u.com