This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Class declaration" Watch "Class declaration" New topic

Class declaration

Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
Many books mention that a "Top Level" java class can be public or not public (i.e not declared with any access modifier). What about the modifiers protected and private, can they be used with top level class ?
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Nope. Top level classes can only be public/default. No other access modifiers permitted....try it out yourself!

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Vishakha Ahuja
Ranch Hand

Joined: Sep 13, 2000
Posts: 191
Thanks Ajith.
J. Macha

Joined: Sep 14, 2000
Posts: 12
What about a private static inner class.
a static inner class is considered a top level class and it can be private.
Ramesh Donnipadu
Ranch Hand

Joined: Sep 16, 2000
Posts: 100
static inner classes (private or otherwise) are top level nested classes. They are not top level classes.
Top level classes are package level classes with only package as enclosing context.

Joined: Sep 16, 2000
Posts: 21
That was nice, Thanks Ramesh!!
I agree. Here's the link:
subject: Class declaration
jQuery in Action, 3rd edition