• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

source code file

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filename = public class name. How are you going to name your file if there are more than one public class ?
 
Darryl Burke
Bartender
Posts: 5149
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic