title: Use of Anonymous Inner Class in java
body: <pre><code>public SampleBehaviour otherway(final String st) {
      return new SampleBehaviour() {
          private String str = st;
  
          @Override
          public void print() {
              System.out.println("val:"+val);
          }
  
      };
  }
  </code></pre>
  
  <p><code>SampleBehaviour</code> is an interface. </p>
  
  <p>Classes that implements an interface must define the methods behavior, whats the use of some variables in interface?</p>
  
  <p>Why does the method parameter need to be final? I don't get some real time application for this type of usage? What's the real thing behind this?</p>
  
  <p>If it's useful, why doesn't C++ have something like this?</p>