1

Is there a way to call a function outside a class? I don't know how to say it but I have an example.

class Class1{
    class Class2{
          public void callFunctionInC1(){
                //how can I call funtionNeedtoBeCalled
          }
    }
    public Class1(){
          Class2 c2 = new Class2();
          c2.callFunctionInC1();
    }
    public void functionNeedtoBeCalled(){
          //do something
    }
 }

It sounds weird but I do have a reason to do that. Is there anyway to do that? Thanks.

YankeeWhiskey
  • 1,522
  • 4
  • 20
  • 32

2 Answers2

8
Class1.this.functionNeedtoBeCalled();

Here is a link with some more discussion. http://www.velocityreviews.com/forums/t137884-inner-class-explicit-outer-class-method-call.html

Calling outer class function from inner class

Community
  • 1
  • 1
Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
4

Yes: Class1.this.functionNeedtoBeCalled();

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80