File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java concepts 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 "java concepts" Watch "java concepts" New topic
Author

java concepts

Abhishek kumar Singh
Greenhorn

Joined: Jan 17, 2009
Posts: 4
why there can be only one public class in a source code file?

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11257
    
  16

This has been asked many times in this forum. You may want to try searching for more details, but the short and simple answer is because it makes writing the compiler easier.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
There can be only 1 public upper level class in a .java file because javac references the file by the name for compiling when delared public. The .java file containing the public class must have the same name as that of the class. Moreover, a file can have only 1 name, so only 1 public class

But there can be any number of inner public classes.


Experience and talent are independent of age
 
Consider Paul's rocket mass heater.
 
subject: java concepts