aspose file tools*
The moose likes Java in General and the fly likes can a class be declared static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "can a class be declared static?" Watch "can a class be declared static?" New topic
Author

can a class be declared static?

Yogesh Kodgule
Greenhorn

Joined: Oct 02, 2003
Posts: 29
When I read phillip heller's Java Certification Book,
It mentioned that a class can't be declared static.
but recently one of my colleagues came up with a code showing a class
declared as static and still it works fine.
is this due to the version difference?
what could be the reason?
what's the fact?
regards,
Yogesh


"Thinking of doing something is also doing something ...so don't just stop thinking!"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Inner classes can be static; such a class, unlike a normal inner class, doesn't have an enclosing instance. But top-level classes can't be static.


[Jess in Action][AskingGoodQuestions]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Inner classes can be static
Not by Sun's definition. Nested classes can be static - but if they're static, they're not considered to be inner classes.
All classes are either top-level, or nested. If they're nested, they are either static member classes, or they're inner classes. Inner classes are either nonstatic member classes, local classes, or anonymous classes.
Older books may use the term "top-level nested class" in place of static member class. This confusing terminology was removed in JLS 2nd edition; it is now best forgotten. Other books may use the term "static inner class". This terminology was never correct according to the official definitions, though some Sun sources gave contradictory info. But Sun has been fairly clear about this for some time now: inner classes are nested classes that are not static. Period. All dissenters will be shot.


"I'm not back." - Bill Harding, Twister
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Grrrr. Language lawyers...
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Yogesh Kodgule
Greenhorn

Joined: Oct 02, 2003
Posts: 29
Thanks for this reply..........
which is not simple, not neat and hopefully not wrong
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can a class be declared static?