Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.
Static
nested classes are accessed using the enclosing class
name:
OuterClass.StaticNestedClass
For example,
to create an object for the static nested class, use this
syntax:
OuterClass.StaticNestedClass nestedObject =
new OuterClass.StaticNestedClass()
Objects that are instances of an
inner class exist within an instance of the outer class. Consider
the following classes:
class OuterClass {
...
class InnerClass {
...
}
}
An instance
of InnerClass can exist only within an instance of OuterClass and
has direct access to the methods and fields of its enclosing
instance.
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
OuterClass.InnerClass innerObject = outerObject.new InnerClass();
8) Is an inner class able to access only
Final Outer variables ?
Yes, Inner class could access only the
“final” outer instance
variables.
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.