| Author |
Inner classes -doubt on static
|
Deepak Kumar
Greenhorn
Joined: Jul 21, 2005
Posts: 15
|
|
The following code works: public class Temp { public void method(){ class Inner{ static final int x = 4; } System.out.println(new Inner().x); } } But why not this??? public class newTemp { class newInner{ static int x = 4; } } } Pls let me know. Thanks.
|
 |
Saurabh Chaubey
Ranch Hand
Joined: Oct 16, 2005
Posts: 101
|
|
Hi Deepak, If you declare a non-static inner class then you cannot have static members in that although static final members are ok as they are compile-time constants. However, if you declare a an nested interface in a class then it can have static members as nested interfaces are implicitly static. Please correct me if i am wrong!! Regards, Saurabh
|
 |
hemamalini s.
Greenhorn
Joined: Oct 17, 2005
Posts: 13
|
|
static classes,interfaces,variables and methods are top-level element.They can be nested within static construct or top level classes only Thanx
|
 |
 |
|
|
subject: Inner classes -doubt on static
|
|
|