Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Class (Var. init)

 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
( I ) why the non final static variable which has been initialized in the outer class - giving error on being used in the inner class - but does not give error on being used by the outer class for the initialization of final static variables ?

eg:




( I I ) Why we cannot use static final int variable of outer class - { initialized in a static block } to initialize a static final int variable of the inner class .


Thanks,
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok got the answer : (Posting here for info)
the problems with above code snippet can be understood with efollowing rules

1. inner classes cannot have static declarations.
2. For non static inner class : One cannot initialize static final variables (declared in the non static inner class), with non static final variables of outer class or static final variables not initialized where declared. (or initialized in static block)

(<<For nested static class : the above (1 & 2) is possible.>>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic