为什么Java文件中只有1个公共类 [英] Why only 1 public class in Java file

查看:126
本文介绍了为什么Java文件中只有1个公共类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何Java文件中,为什么我们只能有一个名称与Java文件名相同的公共类?

In any Java file, why can we have only one public class whose name is same as the Java file name?

推荐答案

它强制所有Java代码以某种方式组织,从长远来看,这有助于提高代码可读性

It forces all Java code to be organized in a certain way, which in the long run helps improve code readability.

Java设计师选择了一种严格的方法来强化他们对良好设计实践的理念,这也是该主题的一部分。与Perl中任何事物的态度形成鲜明对比。

The Java designers chose a strict approach that enforces their idea of good design practices, and this is part of that theme. Contrast that with the anything-goes attitude in Perl.

这篇关于为什么Java文件中只有1个公共类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆