DEV Community

James
James

Posted on

What is encapsulation in C++?

What is encapsulation in C++?
Encapsulation in C++ means binding of data with the functions that performs actions on that data. Encapsulation keeps us safe from outside interference and misuse. And that led us to the important concept of OOP which is data hiding. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing the interference with them.

Data hiding
Data hiding is also a concept of Object Oriented Programming (OOP) that hides details of internal objects.
The belief behind data hiding is to conceal data within a class, so it can be prevented or protected to be accessed by the outside class. Data hiding helps us to create classes with unique data sets and functions by avoiding unnecessary penetration from other program classes.
There is a slight difference between data hiding and data encapsulation, data hiding hides only class data elements, whereas data encapsulation hides class data parts and private functions/methods.

Top comments (0)