Why can't we define a top level class as private?

前端 未结 10 2115
情书的邮戳
情书的邮戳 2020-12-07 12:38

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\"?

10条回答
  •  执笔经年
    2020-12-07 13:19

    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.

提交回复
热议问题