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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why can Watch "Why can New topic
Author

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

Woo Hwang
Greenhorn

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
Author
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="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Cindy Glass
"The Hood"
Sheriff

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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Why can't I use static/private modifiers in outer classes?
 
Similar Threads
Doubt - Dan Chisholm's Inner classes
remembering access modifiers
static class
two questions--please help
why we cann't make a class private and protected