File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regarding top level classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regarding top level classes " Watch "regarding top level classes " New topic

regarding top level classes

vatsalya rao
Ranch Hand

Joined: Feb 14, 2007
Posts: 63
till now i understood that a top level class cant be private means any class that contains "MAIN" method cannot be private.

see the following code:

private class Base{}
public class Vis
transient int iVal;
public static void main(String elephant[])
when this code is compiled syaing that the class "Base" can not be private.
a top level class cant be private means any class that appears at first cant be private?
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
For classes there can only be the public or default access

The following code will also not compile

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Ravi Pinnaboyina

Joined: Feb 19, 2007
Posts: 11
Top level classes mean that classes that are not inner classes, not the classes which have a main method.
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
except for public, final and default(ie if modifier not specified), none of the access modifiers can be used with a class.

hence your code will not compile
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
There can be any no. of toplevel classes. But we can give only public or defalult access specifiers.

It's not that the main method() should only be in top-level class. Main method can also be in inner class, but they can be declared private.

SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
murthy ramana

Joined: Feb 14, 2007
Posts: 10
hi folks,

i think inner classes cant have static declarations - so we cant write main() in an inner class.

thanks and regards,
murthy kvr
I agree. Here's the link:
subject: regarding top level classes
jQuery in Action, 3rd edition