View RSS Feed

Java Object

Inner Classes

Rate this Entry
by , 04-26-2012 at 06:01 PM (819 Views)
Inner class has a link with enclosing class instance just the way with instance methods & variables. It also has a direct access to fields and methods of the object. Because of the association of the inner class with an instance, static member cant be defined by it.

Inner classes instances i.e. object are present in outer class instance. Let us consider these classes:
Java Code:
class OuterClass {
    class InnerClass {
Innerclass’s instance just can exist in the Outerclass instance & also possess the direct access to enclosing instance’s fields and methods. This has been illustrated as following:

Name:  1.jpg
Views: 65
Size:  3.7 KB
Inner Classes

For instantiation of the inner class, outer class shall be instantiated first of all. After this, inner object shall be created in out object, with this syntax:
Java Code:
OuterClass.InnerClass innerObject = InnerClass();
In addition to this, 2 kinds of the inner classes are: anonymous classes and local classes.

Submit "Inner Classes" to Facebook Submit "Inner Classes" to Digg Submit "Inner Classes" to Submit "Inner Classes" to StumbleUpon Submit "Inner Classes" to Google