What is the importance of using the private access specifier in a program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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

When is it necessary for me to use it.

25th Jan 2020, 10:13 AM
Joshua Evuetapha
Joshua Evuetapha - avatar
7 Answers
+ 5
Read the two answers by MeanMachine in the question below: https://www.sololearn.com/Discuss/1799032/
27th Jan 2020, 5:43 AM
David Carroll
David Carroll - avatar
+ 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
25th Jan 2020, 10:58 AM
Artemis Ariamehr
Artemis Ariamehr - avatar
+ 4
To hide your data members from accessing outside of the class
26th Jan 2020, 10:13 AM
Yaseen Akbari
Yaseen Akbari - avatar
+ 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.
27th Jan 2020, 4:29 AM
Sonic
Sonic - avatar
+ 3
Abstraction
25th Jan 2020, 10:53 AM
Gevork Bagratyan
+ 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.
25th Jan 2020, 10:42 AM
Jnn
Jnn - avatar