This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Top Level Public Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Top Level Public Class" Watch "Top Level Public Class" New topic
Author

Top Level Public Class

kumar bangali
Greenhorn

Joined: Dec 01, 2001
Posts: 27

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


Bos Indicus
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
vishal avad
Ranch Hand

Joined: Nov 29, 2001
Posts: 45
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

Joined: Dec 01, 2001
Posts: 27
Thanks Jane and Vishal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Top Level Public Class
 
Similar Threads
(top level class) vs (a nested top level class)
why we cann't make a class private and protected
accessibility specifier of top-level class
Top level class??