• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Top-Level Non Inner Class!

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Java says "We can have as many top-level classes in one source file as you we like, but ONLY one can be declared public and the source file name must match the public class name."

WHY the all class can't be declared PUBLIC? could you please explain?
Thanks.
[ July 01, 2004: Message edited by: Tulsi Rai ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public classes are located by searching the directories in your CLASSPATH for class files with a filename starting with your class name. If a source file had more than one public class, which name would javac give the class file?
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer can be found here.
So the compiler will look for a public wet.sprocket.Toad class/interface in the wet/sprocket/Toad.java file. But if the wet/sprocket/Toad.java file could contain another public class/interface, eg Frog, the compiler has no knowledge how to find a source file for Frog (Toad.java?!).
This is an "optional restriction on compilation units in file-based implementations."
[ July 01, 2004: Message edited by: Irina Goble ]
 
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic