• Post Reply Bookmark Topic Watch Topic
  • New Topic

beginner question: why the source file's name must be the same with the public class?  RSS feed

 
yang lei
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why the source file's name must be the same with the public class?

another quetion is : if the same source file contains more than one public classes ,which name should I take as the file name ? maybe the one contain the main method I think, but if all of them does not contain the main method, what should I do?

thanks very much!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by yang lei:
...if the same source file contains more than one public classes ,which name should I take as the file name? ...

Welcome to JavaRanch!

If the same source file contains more than one (top-level) public class, then it doesn't matter what you name it, because it won't compile.

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.
 
rohit leeta
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Oak 0.2 specification appears to suggest this was a performance optimization.


Interesting research.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!