| Author |
possible to instantiate Inner Class by itself
|
Niyas Ahmed Sheikh
Ranch Hand
Joined: Jun 15, 2005
Posts: 129
|
|
Whether it is possible to instantiate Inner Class by itself! If not, I have got the below coding in this forum. How they instantiate Inner Class like this myAA my= new myAA(); class AA { int x=123; public int getMyVal() { return x; } } public class Test10 { public AA getRef() { final int x=90; class myAA extends AA { public int getMyVal() { return x; } } myAA my= new myAA(); return my; } public static void main (String[] args) { Test10 t =new Test10(); AA a=t.getRef(); System.out.println("Value ---> "+a.getMyVal()); } }
|
 |
soumya ravindranath
Ranch Hand
Joined: Jan 26, 2001
Posts: 300
|
|
myAA is a local class inside a method. Its type is not available outside of the method, you may have noticed that the getRef() method has a return type of the parent class AA. The instantiation is done inside the method, that is fine. [ June 24, 2005: Message edited by: soumya ravindranath ]
|
 |
 |
|
|
subject: possible to instantiate Inner Class by itself
|
|
|