The basic tenet of object-oriented programming is encapsulation. It entails combining data methods and properties. Sensitive information must remain hidden from users.
Encapsulation is regarded as a good practise, in which qualities should always be made private so they can’t be changed unless needed. As a result, the data is ultimately more secure. Methods to access or modify members should be declared once they have been made private.
An illustration of the process of encapsulation is
#include <iostream>
using namespace std;
class class_name
{
private:
int a;
public:
void setA(int num)
{
a = num;
}
int getA()
{
return a;
}
};
int main()
{
class_name obj;
obj.setA(5);
cout << obj.getA() << endl;
}
Output:
5