File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes possible to instantiate Inner Class by itself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "possible to instantiate Inner Class by itself" Watch "possible to instantiate Inner Class by itself" New topic
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: possible to instantiate Inner Class by itself