• 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 Public Class

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi
I am pretty much a greenhorn and just about got started preparing for the certification exam. I need a clarification. According to RHE there can 'generally' be only one top level public class. Are there any exceptions?
------------------
Bos Indicus
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kumar,
A source file can contain more than one top level class but only one top level class can be declared public. (A top level class is not enclosed within the declaration of another class).
For example,
<code>
public class TopOne {}
class TopTwo {}
class TopThree {}
</code>
The above declarations can all appear in one source file. The file must be saved as <code>TopOne.java</code> (it has to match the name of the public top level class).
However, the following source file would produce a compile error:
<code>
public class TopOne {}
public class TopTwo {}
class TopThree {}
</code>
as it declares more than one public top level class.
Hope that helps.

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi kumar
i just wanted to add a bit to what jane has said that
it is not neccessary that a source file must contains a public class.
rgds
vishal
 
kumar bangali
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jane and Vishal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic