title: Call backs in Java (code explanation)
body: <p>I came across this <a href="https://stackoverflow.com/questions/443708/callback-functions-in-java">question</a> about callbacks in Java. Hers is the running <a href="http://ideone.com/Lhv9Y" rel="nofollow noreferrer">code</a> and original answer <a href="https://stackoverflow.com/questions/443708/callback-functions-in-java/443741#443741">here</a>. </p>
  
  <ol>
  <li>But I didn't understand how is it useful for callback?   </li>
  <li>Can you explain the concept of callback to a Java programmer?</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>public class Main {
  
      public interface Visitor {
          int DoJob(int a, int b);
      }
  
  
      public static void main(String[] args) {
          Visitor adder = new Visitor(){
              public int DoJob(int a, int b) {
                  return a + b;
              }
          };
  
          Visitor multiplier = new Visitor(){
              public int DoJob(int a, int b) {
                  return a*b;
              }
          };
  
          System.out.println(adder.DoJob(10, 20));
          System.out.println(multiplier.DoJob(10, 20));
  
      }
  }
  </code></pre>