In java at least, my compiler won't let me put two (or more) separate classes in a single class file. It forces me to create multiple files in the same package. I understand why this is, and I agree with this principle. However, I've realized that I could just as easily nest the classes and contain the entire program (excluding imported libraries) in a single file. I would imagine that this would be frowned upon, but I don't understand why. What are the dangers and disadvantages of nesting class as opposed to the standard system (outside of the severe loss in organization and neatness)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Well, if you keep everything in the same file, you lose packages and the private keyword does no longer have any meaning.
Given that most Java projects will be opened in an IDE that presents different classes as different tabs, you can have more that one cursor in the program.
Why would you have everything in the same file?