File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Why can't I use static/private modifiers in outer classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why can Watch "Why can New topic

Why can't I use static/private modifiers in outer classes?

Woo Hwang

Joined: Aug 07, 2001
Posts: 13
In case of an inner class, what I learnt is that all modifiers except transient can be used, but when I used private or static modifiers in front of ordinary classes, compile error occured. Can someone tell me why?
Sam Dalton
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
Hmm, a private top level class.... can't think of a use for it really, it can NEVER be accessed....
Outer classes are NEVER static, athough their methods may (obviously) be static.

<a href="" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of []Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Like Sam said, a private top level class would be useless.
Something that is static has to be static in relation to something else. A variable or method is static in relation to the class that encloses them. That is to say- the variable or method is valid only at the enclosing class level.
If you try to make the top level class static, what would it be static in relation to? Doesn't make sense.
A nested class can be static in relation to the enclosing class (of course then it is no longer termed an "inner" class).

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Why can't I use static/private modifiers in outer classes?
It's not a secret anymore!