Possible Duplicate:
Java: Why can we define a top level class as private?
Why can't we declare a private outer class? If we can have inner private class then why can't we have outer private class...?
Possible Duplicate:
Java: Why can we define a top level class as private?
Why can't we declare a private outer class? If we can have inner private class then why can't we have outer private class...?
You can't have
private
class but you can havesecond
class:Also remember that
static
inner class is indistinguishable of separate class except it's name isOuterClass.InnerClass
. So if you don't want to use "closures", use static inner class.To answer your question:
You can, the distinction is that the inner class is at the "class" access level, whereas the "outer" class is at the "package" access level. From the Oracle Tutorials:
Thus, package-private (declaring no modifier) is the effect you would expect from declaring an "outer" class private, the syntax is just different.
You can.
private makes the class accessible only to the class in which it is declared. If we make entire class private no one from outside can access the class and makes it useless.
Inner class can be made private because the outer class can access inner class where as it is not the case with if you make outer class private.
Private outer class would be useless as nothing can access it.
See more details:
Java: Why can we define a top level class as private?
private
modifier will make your class inaccessible from outside, so there wouldn't be any advantage of this and I think that is why it is illegal and onlypublic
,abstract
&final
are permitted.Note : Even you can not make it
protected
.