Why can't I use static/private modifiers in outer classes?
Joined: Aug 07, 2001
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?
Joined: Jul 26, 2001
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>
Joined: Sep 29, 2000
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