Why does Java not allow a top level class to be declared as private? Is there any other reason other than \"We can\'t access a private class\"?
We can not declare an outer class as private. More precisely, we can not use the private access specifier with an outer class. As soon as you try to use the private access specifier with a class you will get a message in Eclipse as the error that only public
, final
, and abstract
can be used as an access modifier with a class.
Making a class private does not make any sense as we can not access the code of its class from the outside.