hi,
Through getter setter methods we can indirectly access private data members of the class
as shown in the below code. Then what is the significance of encapsulation in OOPS concept. I am not getting the appropiate answer for that. Can anyone help me?
Thanks in advance
#include<iostream>
using namespace std;
class Test
{
private:
int a;
int b;
public:
void setValue(int val)
{
a=val;
}
int getValue()
{
return a;
}
};
int main()
{
Test objTest;
objTest.setValue(1);
int result=objTest.getValue();
cout<<result<<endl;
return 1;
}