Why cann't we have two public classes in one file....
Neil - 17 Apr 2007 06:40 GMT
> Why cann't we have two public classes in one file....
How?
Daniel Pitts - 17 Apr 2007 07:56 GMT
> Why cann't we have two public classes in one file....
Because the convension is that a public class must be defined in a
file with that same name.
A file cannot have two names, and therefore must contain at most one
public class.
Note that you can have as many non-public classes are you want, and
you also don't have to have any public classes.
Piotr Kobzda - 17 Apr 2007 09:05 GMT
> Why cann't we have two public classes in one file....
We can have as many public classes as we want in one compilation unit --
one-or-more top-level, and zero-or-more nested classes.
Limit of one public top-level class per compilation unit is optional
restriction imposed only when packages are stored in a local file
system. According to JLS (7.7.2), this restriction must not be imposed
when packages are stored in a database.
piotr
Piotr Kobzda - 17 Apr 2007 09:11 GMT
> Why cann't we have two public classes in one file....
We can have as many public classes as we want in one compilation unit --
one-or-more top-level, and zero-or-more nested classes.
Limit of one public top-level class per compilation unit is optional
restriction imposed only when packages are stored in a local file
system. According to JLS (7.2.2), this restriction must not be imposed
when packages are stored in a database.
piotr
Chris Smith - 18 Apr 2007 13:35 GMT
> Why cann't we have two public classes in one file....
You can't do it because of a completely arbitrary choice made by the
implementor of your compiler. The Java Language Specification suggests
it, but it's not really even a requirement of the Java language.
Presumably, your compiler implementor made this choice because he or she
felt that it is a good idea for you to organize code that way; and that
it would be helpful for the compiler to enforce this.

Signature
Chris Smith