Difference between Encapsulation and Abstraction

后端 未结 15 1170
萌比男神i
萌比男神i 2020-12-07 07:21

I had an interview today. I had a question from OOP, about the difference between Encapsulation & Abstraction?

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 08:06

    Encapsulation:

    Hiding something, sort of like medicine capsule. We don't know what is in the capsule, we just take it. Same as in programming - we just hide some special code of method or property and it only gives output, same as capsule. In short, encapsulation hides data.

    Abstraction:

    Abstraction means hiding logic or implementation. For example, we take tablets and see their color and but don't know what is the purpose of this and how it works with the body.

提交回复
热议问题