what is the need to keep the class private? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

what is the need to keep the class private?

16th Jul 2016, 6:00 AM
Kiran Kumari
Kiran Kumari - avatar
3 Answers
+ 1
The private access modifier is accessible only within class. Simple example of private access modifier let'say we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is compile time error. Note : We don't keep our main outer class as private ..generally class members are kept private to achieve encapsulation.
15th Aug 2016, 1:07 PM
Abhishek C Prajapati
Abhishek C Prajapati - avatar
0
to protect from other method and class.... and we always make inner class as private not outer class...
16th Jul 2016, 11:30 AM
€¥~RTH~€¥
€¥~RTH~€¥ - avatar
0
only reason is to provide security to the class because any programmer would not like that his sensitive data to be accessed by unknown user
5th Aug 2016, 2:06 AM
sachin tomar
sachin tomar - avatar