aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Public class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Public class" Watch "Public class" New topic
Author

Public class

Ganesh Kumar
Greenhorn

Joined: Dec 18, 2006
Posts: 11
Why only one public class is allowed per source code file? what they are achieving by having that rule?
Anuragk kushwaha
Ranch Hand

Joined: Aug 02, 2006
Posts: 51
Hi Ganesh,,

JVM is a program which is outside your package. since execution point of any prog is main() which must be defined in a public class, because it is accesed by jvm which is outside the package.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The Oak 0.2 specification appears to suggest this was a performance optimization.
Although each Oak compilation unit can contain multiple classes or interfaces, at most one class or interface per compilation unit can be public... This restriction is ... necessary for efficient package importation.

Ref: Once Upon an Oak.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Public class