title: Instantiate an abstract class or interface, possible?
body: <p>This works good.</p>
  
  <pre><code>package abstracttest;
  
  public abstract class AbstractClass implements NewInter {
  
      public abstract void doStuff();
  
      public void doStuff2() {
          System.out.println("in doStuff2");
      }
  
      /*
       * public static void main(String a[]) { AbstractClass ab = new
       * AbstractClass() {
       * 
       * @Override public void doStuff() { // TODO Auto-generated method stub
       * System.out.println(" doStuff "); }
       * 
       * @Override public void doInter() { // TODO Auto-generated method stub
       * 
       * } };
       * 
       * ab.doStuff2(); ab.doStuff();
       * 
       * NewInter ni = new NewInter() {
       * 
       * @Override public void doInter() { // TODO Auto-generated method stub
       * System.out.println("do Inter"); }
       * 
       * }; ni.doInter();
       * 
       * AbstractClass ab1 = new AbstractClass(); }
       */
  
  }
  
  interface NewInter {
  
      String con = "Hell";
  
      void doInter();
  }
  
  class Impl extends AbstractClass {
  
      @Override
      public void doInter() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void doStuff() {
          // TODO Auto-generated method stub
  
      }
  
      public static void main(String[] s) {
          AbstractClass ab = new AbstractClass() {
  
              @Override
              public void doInter() { // TODO Auto-generated method stub
                  System.out.println("impl doInter");
              }
  
              @Override
              public void doStuff() { // TODO Auto-generated method stub
                  System.out.println("impl doStuff");
              }
  
          };
          ab.doInter();
          ab.doStuff();
  
          NewInter ni1 = new NewInter() {
  
              @Override
              public void doInter() {
                  // TODO Auto-generated method stub
  
              }
          };
          ni1.doInter();
      }
  
  }
  </code></pre>
  
  <p>I was able to instantiate the <code>abstract class</code> and <code>interface</code> both from within the abstract class' <code>main()</code> and from the <code>class Impl</code>.<br>
  How is this possible?<br>
  I was expecting an exception but the invocation worked correctly.<br>
  Can someone please explain the phenomena? I am confused.</p>
  
  <blockquote>
    <p>A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.</p>
  </blockquote>
  
  <p>I read this in a <a href="http://javapapers.com/core-java/abstract-and-interface-core-java-2/difference-between-a-java-interface-and-a-java-abstract-class/" rel="nofollow">blog</a>. What does it mean?  </p>
  
  <p>And is there any other way of invoking the constructor of an abstract class? Please let me know if there is.</p>