• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local inner classes

 
geethal rodrigo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when locan inner class object is created that object can only access within the method because of the variable scope.IS THERE ANY WAY TO ACCESS THE LOCAL INNER CLASS FROM THE MAIN METHOD BY ONLY USING INNER CLASS REFERENCE .I TRYIED EVERYTHING .PLEASE HELP.

class Outer{
void m(){
class Inner{
void m2(){
System.out.println("It works");
}
}
Inner i1=new Inner();
i1.m2();

}
}
class Main extends Outer{
public static void main(String arg[]){
Outer a2=new Outer();
a2.m();
xxxxxxx.m2();
}
}
Like this I want to access m2().
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi geethal,

the only way to use an instance of a local inner class outside of the method, is something like this:
 
geethal rodrigo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much. I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic