Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner classes question

 
Gaurav Mantro
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just confused about why inner classes can't have non-final static members ?
------------------
http://www.mantrotech.com
 
srinivasrao marri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can access final varibale in inner class mention your problem correctly
 
Gaurav Mantro
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner class can't declare static member variables unless they are static final why ?
------------------
http://www.mantrotech.com
 
Dave Terrian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gaurav Mantro
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cindy and Dave. Your explaination helped me to understand the concept.
regards
Gaurav Mantro
------------------
http://www.mantrotech.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic