+ 4
What is the importance of using the private access specifier in a program
When is it necessary for me to use it.
7 Answers
+ 5
Read the two answers by MeanMachine in the question below:
https://www.sololearn.com/Discuss/1799032/
+ 7
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
+ 4
To hide your data members from accessing outside of the class
+ 4
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.
+ 3
Abstraction
+ 2
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.