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 Only One public class per file restriction ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Only One public class per file restriction ?" Watch "Only One public class per file restriction ?" New topic
Author

Only One public class per file restriction ?

Shaan patil
Ranch Hand

Joined: Dec 22, 2007
Posts: 58
Hi folks ,


There is a rule in java which states that
Rule 1.Only one public class per file is allowed.

I tried compiling a file in which I had declared one class as public and other class as dedfault .I got compile error which stated above rule.

What may be the isuue ?


"You cannot change the truth but truth can change you "
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
Most likely because you forgot the other half of that rule:

The file has to have the same name as the public class.

If you gave the file the same name as the default class, it won't compile.
 
Don't get me started about those stupid light bulbs.
 
subject: Only One public class per file restriction ?
 
Similar Threads
Public class
Classes in source file
PACKAGE,IMPORT,CLASS
Class using Main without declaring itself Public
HF Java 2ed