Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Why not two classes...

Thread view: 
Shraddha - 17 Apr 2007 05:23 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.