Encapsulation vs Data Hiding - Java

前端 未结 19 2139
耶瑟儿~
耶瑟儿~ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 08:58

    In the class, attributes and behaviors are placed together. An encapsulation means, that when you create a class, this itself means that you realize encapsulation principle. Because data and behaviors are encapsulated into the class. So data hiding is a major part of the term - encapsulation. And this means access points of the object.

提交回复
热议问题