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 Class (Var. init) 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 Class (Var. init)" Watch "Inner Class (Var. init)" New topic
Author

Inner Class (Var. init)

Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
( 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,


/** Code speaks louder than words */
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
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.>>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner Class (Var. init)