Non-public top-level class vs static nested class

前端 未结 4 1069
情书的邮戳
情书的邮戳 2020-12-14 09:29

It seems to me that non-public top-level classes and static nested classes essentially perform the same tasks when creating a helper class.


A.java


<
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 09:58

    One difference is that a static nested class can be declared public. You cannot do this for any other class in the same file as the primary class as a public main level class must be the same name as the file name.

    So you could declare many public classes in one file, but only one of them being the main level. The other static nested classes ought to be related though to the main class or it really does not make sense to do that.

提交回复
热议问题