Nested classes Here is another advantage of the Java, an object-oriented programming language that allows us to define
a class within another class, such class is called a nested class. Inner
classes can be either named or anonymous.
Static Nested Classes A nested class that is declared static
is called a static nested class. Memory to the objects of any static nested classes
are allocated independently of any particular outer class object. A static nested class use
the instance variables or methods defined in its enclosing class only through an object
Inner Nested Classes
Non-static nested classes are slightly different from static nested classes,
nested class is actually associated to an object rather than to the class in
which it is nested.
Member Classes The class which is define in the body of a
class is called a member class.Member class can be used within the body of the same class. The
member classes can also use of instances of the same class without explicit
delegation. The member class is the only class that can be declare as
classes are same as local initializer and is declared within a code
body (inside a code
of a function or static initializer)of Java. Very rarely local class is defined within a method.
The lacal class can be instantiated so many times as we wish to initialize.
Anonymous Classes Anonymous
classes can be extend a super class and can also implement an interface. We can
it is a
that is defined without a class name,
the anonymous classes are instantiated only once
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.