This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why a non-static member class cannot have static members? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why a non-static member class cannot have static members?" Watch "Why a non-static member class cannot have static members?" New topic
Author

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

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
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

Joined: Aug 17, 2003
Posts: 9
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

Joined: Jul 09, 2004
Posts: 39
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


+nav
Louie van Bommel
Ranch Hand

Joined: Aug 17, 2004
Posts: 76
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
 
subject: Why a non-static member class cannot have static members?
 
Similar Threads
Doubt In Static Memeber...Plz Help Me
Question regarind Inner Classes
Why non-static inner class cannot have static member
Non-static Inner Class
Accessing outer class members in a static nested class.