aspose file tools*
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
Author

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
Greenhorn

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
Greenhorn

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
 
Don't get me started about those stupid light bulbs.
 
subject: regarding top level classes