What is the difference between access modifier private and access modifier public | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between access modifier private and access modifier public

24th Mar 2019, 12:41 PM
alvin
alvin - avatar
2 Answers
+ 7
If you declare any variable with public modifier, then *all* methods (functions) will be able to access that variable's value. But if you declare any variable with private modifier, then only the methods (functions) of the same class can access that variable's value.
24th Mar 2019, 12:45 PM
Letsintegreat
Letsintegreat - avatar
24th Mar 2019, 12:50 PM
Scooby
Scooby - avatar