• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

possible to instantiate Inner Class by itself

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
}
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic