Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can a class be declared static?

 
Yogesh Kodgule
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grrrr. Language lawyers...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Yogesh Kodgule
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this reply..........
which is not simple, not neat and hopefully not wrong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic