For your info, inner and nested classes can be either private or protected. The restriction you're talking about only applies to top-level classes.
A top-level class can only have public or default visibility. Since you understand why a top-level class cannot be private, try applying the same reasoning to figure out why there's no point in allowing a top-level class to be protected, when it can already have default visibility.
we can inner class protected (or private) the restriction applies to top level classes because it simply does not make any sense... think about it theres nothing that you will acheive by making a class protected
The significant problems we face cannot be solved by the same level of thinking which created them – Einstein SCJP 1.5, SCWCD, SCBCD in the making
posted 11 years ago
We have default access for class.. which means we can see that particular class in same package to which it belongs to...
Similarly public class can be seen in any packages...
So if i want my class to be visible in other packages but not to all the classes mean to say i want that class to be visible to subclassess then we could have used this protected modifier rite??
I know there is no use of protected classess but even then why we dont have that... Is there any specific reason for it??
Always remember that Protected Members are accessed through Inheritance and not reference...... It does not make much sense to mark a Top Level class Protected, Public and default do the Job well. You use protected access modifiers for members..... which actually need to be inherited.
[ October 31, 2007: Message edited by: Gaurav Minhas ] [ October 31, 2007: Message edited by: Gaurav Minhas ]
I would like to know it too, why it isn�t possible.
I know, that lots of people tell me, that nobody wants a protected class (Apart from inner classes). Well i don�t know a good reason for wanting it, too.
But that can�t be the reason why it isn�t possible.
Protected means visible to the package and thru inheritance - not visible by reference (at least in other packages).
Is it possible, that the import or the extends statements are seen as reference ? If that would be true, than it wouldn�t make any sense to have a protected class, cause it would be the same as default, since it wouldn�t be visible in other packages.