Hi friends, welcome back to Java Code Online. This article is in continuation to the previous article on Regular Inner Class, here I will discuss the second type of Inner Class called Static Inner Nested Class.
The static Inner Nested Classes are nothing else, but are like Regular Inner class, but are marked static. So the behavior of these classes is static in nature. This explains most of the behavior of the static inner class. Like it behaves like a class level variable. I mean to say that, you need not instantiate the outer class for creating an instance of the static inner class, and that the static inner class can be directly instantiated.
Moreover as the behavior of a static member is, the static inner class cannot access the non static members of the class, this is in sync with the basic properties of a static variable or member of a class. For instantiating a Static Inner Class, you need to use the name of both the Outer class and Inner class. For example:-
OuterClass.InnerClass ocic = new OuterClass.InnerClass();
I hope the article was helpful. In case it was, the do leave a comment.
For reference,
Types of Inner Class
1. Regular Inner Class
2. Method Local Inner Class
3. Anonymous Inner Class
4. Static Nested Inner Class
Keep checking Java Code Online for more Java info.
You might be interested in these too:-
Static Inner Class Example in Java
Hi bro, the explanation is good, but I need some examples on static Inner nested Classes, Hope you could provide them. Thanks.
ReplyDelete