• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can a class be declared static?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Grrrr. Language lawyers...
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Yogesh Kodgule
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this reply..........
which is not simple, not neat and hopefully not wrong
reply
    Bookmark Topic Watch Topic
  • New Topic