Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes source code file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "source code file" Watch "source code file" New topic
Author

source code file

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Why is it that there can be only one public class per source code file , whereas there can be more than one non public class.

Is there any reason ...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Filename = public class name. How are you going to name your file if there are more than one public class ?


[My Blog]
All roads lead to JavaRanch
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

More to the point: because the JLS says so.
http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.6

When packages are stored in a file system (§7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) ...


luck, db
There are no new questions, but there may be new answers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: source code file