Encapsulation vs Data Hiding - Java

前端 未结 19 1910
耶瑟儿~
耶瑟儿~ 2020-12-04 08:29

Interviewer: What is encapsulation and how do you achieve it in Java?

Me: Encapsulation is a mechanism to hide

相关标签:
19条回答
  • 2020-12-04 09:05

    I saw a lots of discussion is already done, just to simplify from my understanding:

    Encapsulation Ensures that the behavior of an object can only be affected through its API. It lets us control how much a change to one object will impact other parts of the system by ensuring that there are no unexpected dependencies between unrelated components.Access modifier can used to achieve Encapsulation.

    Information hiding Conceals how an object implements its functionality behind the abstraction of its API. It lets us work with higher abstractions by ignoring lower-level details that are unrelated to the task at hand. Abstraction at design level can be used to achieve data hiding.

    0 讨论(0)
提交回复
热议问题