Why make a private property? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why make a private property?

Why make a property private if the private field that it accesses can already be accessed from within the class? EDIT: This is my understanding. Some fields should not be made directly accessible from outside the class, and hence they are made private. A public property is therefore required to access this private field (indirectly) from the outside. However, by making the property private, this can only be accessed from inside the class. But then whatever is accessing this private property (from within the class) should also be able to access the private field directly. Therefore, what is the purpose of this private property?

15th Mar 2017, 8:55 AM
Stephen Jukes
3 Answers
0
when making a property primary, ita cannot be accessed outside the class.
14th Mar 2017, 2:14 PM
Yasiru Nayanajith
Yasiru Nayanajith - avatar
0
how to include a javascript intp html?
16th Mar 2017, 5:56 PM
soko
soko - avatar
0
The purpose of the private property is to not make it directly usable outside of the class they are in. It is usually ment for protection of certain parts of your code because we don't want the user to have access to it directly.
17th Mar 2017, 11:27 AM
Dextozz
Dextozz - avatar