Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sura watthana
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Nanda Kishore
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
navneet shrivastava
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Louie van Bommel
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic