• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How many public classes in a source file?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been reading the RHE study guide for certification, and looking back over some of my completed CattleDrive assignments for examples here and there. I notice in the instructor's solution for one assignment (changed here slightly to protect future students) that he starts with a class within a class, BOTH of which are declared public, as in:

How does this fit with the following statement from RHE:

There may be AT MOST ONE PUBLIC class definition per source file...." (emphasis added)


 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think RHE is implying that there may be at most one public top-level class definition per source file...(bold added for emphasis)
In your example, the second public class is an inner class.
-Peter
Ps. You may want to submit to RHE a suggestion to make this explicit in their next edition.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My RHE (Sept 2000 edition) has this in the chapter summary on p. 24:


There should be, at most, one public class definition per source file...


but it's more explicit in the chapter body on p. 4:


A source file should generally contain, at most, one top-level public class definition...


So, the information is there; you just have to read carefully and not depend solely on the chapter summaries.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!