• 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

Why a non-static member class cannot have static members?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm wondering why a non-static member class cannot have static members?
could anybody give me a/some reason(s) for it?

Thank you
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As with instance methods and variables, an inner class is associated with an instance of its enclosing class and has direct access to that object's instance variables and methods. Also, because an inner class is associated with an instance, it cannot define any static members itself.

For details refer:
http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, jus trying to make it more simpler.[note it is as per my understanding]

STATIC member are independent of class.

NON-STATIC members depends on class.
so, a NON-STATIC members class also depends on class.

it means a NON-STATIC member class cant exist by itself.
this is a contradiction with STATIC members.

concluding.. we cant have a STATIC member within a NON-STATIC member class.

hope i put it straight.
-navneet
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sura watthana:
I'm wondering why a non-static member class cannot have static members?
could anybody give me a/some reason(s) for it?



I believe this was a design decision to have only "instances" of the inner class provide services, and to not have the inner class itself provide any services. I don't really see any other reason, either. I'd be interested in hearing from someone who knows about this design decision.
 
reply
    Bookmark Topic Watch Topic
  • New Topic