title: Instantiation of abstract classes
body: <p>I have been reading <a href="https://www.tutorialspoint.com/java/java_innerclasses.htm" rel="nofollow noreferrer">this guide</a> on inner classes and came across this interesting example of an anonymous class.</p>
  
  <p>So, by default we cannot instantiate an abstract class, e.g.</p>
  
  <pre class="lang-java prettyprint-override"><code>abstract class AnonymousInner {
     public abstract void mymethod();
  }
  
  public class Outer_class {
     public static void main(String args[]) {
        AnonymousInner inner = new AnonymousInner();
        inner.mymethod(); 
     }
  }
  </code></pre>
  
  <p>Gives an error stating that we cannot instantiate an abstract class.
  But doing it this way is fine -</p>
  
  <pre class="lang-java prettyprint-override"><code>abstract class AnonymousInner {
     public abstract void mymethod();
  }
  
  public class Outer_class {
     public static void main(String args[]) {
        AnonymousInner inner = new AnonymousInner() {
           public void mymethod() {
              System.out.println("This is an example of anonymous inner class");
           }
        };
        inner.mymethod(); 
     }
  }
  </code></pre>
  
  <p>So I am a bit lost how the second example is working.</p>