Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The Oak 0.2 specification appears to suggest this was a performance optimization.



Interesting research.
reply
    Bookmark Topic Watch Topic
  • New Topic