title: Java: calling outer class method in anonymous inner class
body: <p>Recently, I ran into a mysterious problem in an android project, which I described <a href="https://stackoverflow.com/questions/9039017/android-app-application-cannot-be-instantiated-due-to-nullpointerexception/9039931">here</a>. I somehow solved the problem, but still don't know the exact reason behind it. </p>
  
  <p>Let's say I want to call a function foo() in the inner class. The question is, what's the difference between calling it directly like</p>
  
  <pre><code>foo();
  </code></pre>
  
  <p>or calling it with the outer class instance</p>
  
  <pre><code>OuterClass.this.foo();
  </code></pre>
  
  <p>Besides, i will appreciate if anyone can check my last <a href="https://stackoverflow.com/questions/9039017/android-app-application-cannot-be-instantiated-due-to-nullpointerexception/9039931">question</a> related to this, and give me a clue about why the error occurs. Many thanks.</p>
  
  <p>PS: I read somewhere that the non-static inner class will always hold an instance of the outer class. So it will call outer function using that instance if I only use foo()?</p>