What is the importance of using the private access specifier in a program

When is it necessary for me to use it.

1/25/2020 10:13:29 AM

Joshua Evuetapha

7 Answers

New Answer


Read the two answers by MeanMachine in the question below: https://www.sololearn.com/Discuss/1799032/


This is for encapsulation and abstraction Private modifiers dont get inherit and cant be modified from outside of class and cant be modified on created instance


To hide your data members from accessing outside of the class


This is one of the key features of object oriented programming when you want to have information hiding and encapsulation, especially when you only want limited parts of the program to modify certain data.


https://www.sololearn.com/discuss/1746189/?ref=app https://www.sololearn.com/discuss/826596/?ref=app https://www.sololearn.com/discuss/1799032/?ref=app




If you dont want it to be changed from other classes, with private only this class can access it. Its generally a good style to use private attributes and get and set methoded to modify this attributr instead of public attributes, cause it you change the attribute name you would have to change it everywhere it is used.