Encapsulation is more about keeping a group of code as a discreet work unit but it also has data hiding because you only expose "the method" rather than its inner workings to other classes. Encapsulating leads to data hiding, so that's why it sounds similar.
Data hiding on its own it by only marking those things as a public scope which you want external classes to interact with, and private otherwise. If you don't want other classes or only certain classes to use, you can also use private (current class only), protected (current and children), and internal (treated as public to other classes in the same assembly, private to outside assembly classes) to prevent other classes beyond a certain scope from using your methods/properties/classes.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Can you answer this question?
Write Answer1 Answers