why we can't declare a class as private or protected ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why we can't declare a class as private or protected ?

11th Apr 2017, 6:34 AM
Somnath Ghosh
Somnath Ghosh - avatar
2 Answers
+ 2
Because the whole point of private is to disable usage of the item outside the class they have been defined in. The protected makes the items available to that class and all sub classes of that base class. It simply doesn't make sense to declare a class private or protected since you couldn't use it anywhere.
11th Apr 2017, 7:10 AM
Dextozz
Dextozz - avatar
0
button masher....but if want to encapsulate a class then what we do.. we declare every method and variable private...then also u can't use that class
11th Apr 2017, 3:00 PM
Somnath Ghosh
Somnath Ghosh - avatar