Nested Classes

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Nested Classes

Inner Classes An inner class is a type of nested class that is not explicitly or implicitly declared static. Inner class types Local inner class. o o o o A local class is a nested class that is not a member of any class and that has a name. Every local class declaration statement is contained by a block. The scope of a local class declared in a block is within the rest of the block. Local class defined in a method has access to final method variables and also to the outer class's member variables.

example [More in ebook]

Anonymous inner class. o o Anonymous inner class does not have name. It can extend a class or implement an interface but cannot do both at the same time. (For example, an anonymous inner class cannot say extends and implements at the same time.) The definition, construction and first use of such class is at same place. Programmer cannot define specific constructor for anonymous class but he/she can pass arguments (to call implicit constructor of its super class.) An anonymous class is never abstract. An anonymous class is always an inner class; it is never static. An anonymous class is always implicitly final. Anonymous class defined in a method has access to final method variables and also to the outer class's member variables.

o o o o

[More in ebook]

Non-static member class. o o o o A member class is a inner class whose declaration is directly enclosed in another class or interface declaration. Member inner class can be public, private, protected or default/friendly. Non-static member inner class has access to member variables of the outer class. Non-static member inner class can be instantiated on the instance of the outer class.

example [More in ebook]

Static nested classes. Nested class can also be static. It has access to only static member variables of the outer class. Static nested class may be instantiated/accessed without the instance of the outer class. It is accessed just like any other static member variable of a class. For example, instance method accessTest() of public static nested class "Inner" can be

invoked as...

new com.witscale.scjp.examples.Outer.Inner().accessTest();

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy