| Author |
Static Nested classes
|
Smitha Amresh
Greenhorn
Joined: Jun 13, 2005
Posts: 6
|
|
Hi All, I am studying about static nested classes and I am surprised to know that we can create instances of static nested classes. public class Test{ public static void main(String[] arg){ Test.staticTest t = new Test.staticTest(); Test.staticTest t1 = new Test.staticTest(); } public static class staticTest{ } } According to my understanding when we append static modifier that means we have a single instance associated with a class not instance of the enclosing object. Then isn't it logically wrong procedure to create static class instance?? Please explain me how is it possible. Thanks in advance, Smitha
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
A static variable in a class is shared by all instances of that class in a JVM for a class loader. Now, a class definition is different than a variable declaration. A class is declared static so that it can be accessed statically(without an instance) from static/non-static blocks in same/other classes. This does not mean that all instances of that class will be static. It is perfectly legal to define an instance variable of a static class. You need to understand that it is just the class "definition" that is static.
|
apigee, a better way to API!
|
 |
 |
|
|
subject: Static Nested classes
|
|
|