GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

We can access and modify a private data member of a class by using a public member function, then what is the use of access modifires ?

asked Nov 5, 2016 by Rahul Kumar 64

2 Answers

Basically, Private modifier used to achieve  the security means our data should not go out side directly or out side person can't access our data directly but after validation or verification  a valid customer can access private data. This verification or validation code written inside the public member function so that only a valid user can access private data. 

answered Nov 23, 2016 by vivekcs0114
Access specifiers are the excellent features of oops.Bec data security and data hiding is only happens through those type of specifiers. If we use public access specifier any one can access from it and especially main ( ) fun access through public only. While coming to private access specifier it hides the data.As u said we can access the data through public but it is based on user only whether he has to get the data or not. Accoding to me without private ,data security cant be see. I hope u can understand
answered Nov 27, 2016 by Yashu guntur
...