File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes y  a non_static inner class cant have static members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "y  a non_static inner class cant have static members" Watch "y  a non_static inner class cant have static members" New topic
Author

y a non_static inner class cant have static members

Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
ive seen that a non-static inner class cant have static members but why does java put this restriction
again why cant a constructor be synchronized
cherry
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Cherry,
A static member belongs to the class. Guarantees that only one copy of the member will exist. There's really no need to allow the use of static in an inner class. If you need such a member, you can just as easily define it in the outer class as you can only create an inner class object if you already have an outer class object.
Constructors are used to create instances of the class. Not sure why you would need to synchronize the creation of an object; usually you synchronize to ensure an object is only updated/modified by one thread at a time.
Hope that helps.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
i got the answer why constructors cannot be synchronized thatz bcos v didnt create an object then how can u synchronized on the object
but still im not clear why a non-static inner class cannot have a static members. if v have a static member v can hide it from the outer class and also let inner classes access it .
waiting for a reply bill any answers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: y a non_static inner class cant have static members