Why are filenames in Java the same as the public c

2018-12-31 16:30发布

In Java, the name of the file should be the same as the name of the public class contained in that file. Why is this a limitation? What purpose does it serve?

标签: java
7条回答
冷夜・残月
2楼-- · 2018-12-31 17:31

As long as it is not public a class can have a name different from its file name. The class can also have main method. Class file will be generated with the class name but not with the source file name. The class name should be used to execute it.

Reason is: default class is package private, thus javac doesn't have to find this source file of this to compiler some other java program from outside of package.

查看更多
登录 后发表回答