Nested classes vs Separate class files

折月煮酒 提交于 2019-12-01 17:11:43

问题


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?



来源:https://stackoverflow.com/questions/35027314/nested-classes-vs-separate-class-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!