I was just wondering in my program, what exactly is the purpose of declaring private data members? What exactly is the concept behind, private and public?
Code:
#include<iostream>
using namespace std;
class Encapsulation /*class name is Encapsulation */
{
private: /*access specifer */
int x; /* x is integer variable that store integer value */
public: /*access specifer */
void set(int a) /*function that pass integer value a */
{
x =a; /* we are assigning content of a to x */
}
int get() /* function that resturn value of x */
{
return x; /*return result of x */
}
};
int main() /* start program */
{
Encapsulation obj; //declare object of job */
obj.set(5); // call function to pass 5
cout<<obj.get(); /* get output of function
return 0;
}