title: What is the purpose of the default keyword in Java?
body: <blockquote>
    <p>An interface in Java is similar to a class, but the body of an
    interface can include <strong>only abstract methods</strong> and <code>final</code> fields
    (constants).</p>
  </blockquote>
  
  <p>Recently, I saw a question, which looks like this</p>
  
  <pre><code>interface AnInterface {
      public default void myMethod() {
          System.out.println("D");
      }
  }
  </code></pre>
  
  <p>According to the interface definition, <strong>only abstract methods</strong> are allowed. Why does it allow me to compile the above code? What is the <code>default</code> keyword?</p>
  
  <p>On the other hand, when I was trying to write below code, then it says <code>modifier default not allowed here</code></p>
  
  <pre><code>default class MyClass{
  
  }
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>class MyClass {
  
  }
  </code></pre>
  
  <p>Can anyone tell me the purpose of the <code>default</code> keyword? Is it only allowed inside an interface? How does it differ from <code>default</code> (no access modifier)? </p>