Tuesday, 19 April 2011

How to create an inner class instance from outside the outer class instance code?

To create an instance of the inner class you must have the instance of its enclosing class.
e.g. class EnclosingOuter {
class Inner{ }
}
 To create the instance of inner class from class other than the enclosing class.
1) class OtherThanOuter{
EnclosingOuter out = new EnclosingOuter();
EnclosingOuter.Inner in = out.new Inner();
}

2) class OtherThanOuter{
EnclosingOuter.Inner out = new EnclosingOuter.Inner (); }

No comments:

Post a Comment