Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing method in a static Inner Class

 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cosidering this code is it possible to access aMethod()?? if it is, then how?
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to access method from static inner class there is no need of Outer class instance.since it is static we can use the direct name.
Outer.Inner.amethod();
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code you posted will be true iff the aMethod was static (which isn't)
add the following code to previous and see the result yourself

both ways(line 1 & 2) to access aMethod() failed... i think it is impossible to reach, anyone else agrees???
 
sopal Pal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do something like this, this works
==================
public static void main(String[] args)
{
Outer.Inner i = new Outer.Inner();
i.aMethod();
}
================
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic