Passing anonymous class
<p>I am passing an interface as anonymous implementation to a different object like this:</p>

<pre><code>public interface Interface {
    public int convert (int a);
}



public static void main(String[] args) throws IOException, InterruptedException {

  final int[] array = {1,6,3,5,7,8,4,0,3};
  Interface inter = new Interface() {           
      public int convert(int a) {
         int result = a;                
         for (int i = 0; i &lt; array.length; i++) {
         a=a+array[i];
         }              
         return a;
      }
   };

  SomeObject ty = new SomeObject ();
  ty.Test(7, inter);
}

public class SomeObject {   

  public void Test(int number, Interface inter) {               
    System.out.println(inter.convert(number));
  }
}
</code></pre>

<p>My question is: how does it work? How does <code>SomeObject</code> know about the array which is not passed directly to the object (array is not a member of the anonymous class).</p>

<p><strong>Update</strong><br>
(sorry for late update) </p>

<p>what about member vars or methods methods that are used in the anonymous class? they are not final</p>

<pre><code> Interface inter = new Interface() {            
          public int convert(int a) {
             int result = a + someMemberVar;                
             for (int i = 0; i &lt; array.length; i++) {
             a=a+array[i];
             }              
             return a;
          }
       };
</code></pre>
