InterviewSolution
| 1. |
How To Create An Inner Class Instance From Outside The Outer Class Instance Code? |
|
Answer» To CREATE an instance of the inner CLASS you MUST have the instance of its enclosing class. class Enclosing OUTER { class Inner{ } } To create the instance of inner class from class other than the enclosing class. 1) class OtherThanOuter { Enclosing Outer out = new Enclosing Outer (); EnclosingOuter.Inner in = out.new Inner (); } 2) class OtherThanOuter { EnclosingOuter.Inner out = new EnclosingOuter.Inner (); } To create an instance of the inner class you must have the instance of its enclosing class. class Enclosing Outer { class Inner{ } } To create the instance of inner class from class other than the enclosing class. 1) class OtherThanOuter { Enclosing Outer out = new Enclosing Outer (); EnclosingOuter.Inner in = out.new Inner (); } 2) class OtherThanOuter { EnclosingOuter.Inner out = new EnclosingOuter.Inner (); } |
|