Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What are the differences between static or non-static inner classes?

0
10 Posted

What are the differences between static or non-static inner classes?

0
10

• There is no such thing as a static inner class. There are top-level classes and nested classes, and nested classes are by definition divided into static and inner. • If it is static, it is not inner class, you can use it just as top-level class, but put a qualifier as EncloseingClass.EnclosedClass. • If inner class is a member of enclosing class, it must be attached to an instance of the Enclosing class, something like new EnclosingClass().new EnclosedClass(). • Local and anonymous classes are also inner classes, they can be defined in methods, initializers, which will be local to that enclosing scope. • Since the scope can be instance or static, Local and anonymous classes can be defined in an instance or a static context. • Attention: JLS2 has got rid of “Nested top-level class” confusing terminology now. The correct name now is static member class, which in contrary to inner class (non-static member class) in JLS2 now. • See more in Classes in JLS2 • See an Inner/Nested/Local Clas

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123