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 Inner classes question 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 "Inner classes question" Watch "Inner classes question" New topic
Author

Inner classes question

Gaurav Mantro
Ranch Hand

Joined: Sep 08, 2000
Posts: 61
I am just confused about why inner classes can't have non-final static members ?
------------------
http://www.mantrotech.com


----------------------<br />regards.<br /><a href="http://www.mantrotech.com/editors/gaurav_mantro.asp" target="_blank" rel="nofollow">Gaurav Mantro</a><br /><a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">Java Information Portal</a> - <a href="http://www.mantrotech.com/technology/java/index.asp" target="_blank" rel="nofollow">http://java.mantrotech.com</a>
srinivasrao marri
Ranch Hand

Joined: Feb 13, 2001
Posts: 61
u can access final varibale in inner class mention your problem correctly
Gaurav Mantro
Ranch Hand

Joined: Sep 08, 2000
Posts: 61
Inner class can't declare static member variables unless they are static final why ?
------------------
http://www.mantrotech.com
Dave Terrian
Greenhorn

Joined: Jun 25, 2000
Posts: 15
We can "say, loosely, that the static keyword always marks a 'top-level' construct (variable, method, or class), which is never subject to an enclosing instance."
"This shows why an inner class cannot declare a static member, because the entire body of the inner class is in the scope of one or more enclosing instances."
See here
- Dave
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
By definition EVERYTHING that the inner class has, that can be manipulated in any way (is not a constant), must be in relation to an instance of the outer class. So each outer class instance would need to have it's OWN version of the inners static member. But you can't have multiple copies of a static thing. So you just can't do it.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Gaurav Mantro
Ranch Hand

Joined: Sep 08, 2000
Posts: 61
Thanks Cindy and Dave. Your explaination helped me to understand the concept.
regards
Gaurav Mantro
------------------
http://www.mantrotech.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner classes question