title: Understanding the purpose of Abstract Classes in Java
body: <p>Suppose I have two Classes, A and B. The A class is defined as abstract, while B extends this abstract class, and finally i test the result and both classes are part of same package.  </p>
  
  <pre><code>public abstract class A {
  
      protected abstract void method1(); 
  
      protected void method2() { 
          System.out.println("This is Class A's method"); 
      } 
  }
  
  public class B extends A {
  
      @Override
      protected void method1() {
          System.out.println("This is B's implementaiton of A's method");
      } 
  }  
  </code></pre>
  
  <p>and now when i test them:  </p>
  
  <pre><code>B b = new B();
  b.method1();
  b.method2();  
  </code></pre>
  
  <p>I get expected output:  </p>
  
  <pre><code>This is B's implementaiton of A's method
  This is Class A's method
  </code></pre>
  
  <p><strong>QUESTIONS:</strong>  </p>
  
  <ul>
  <li>What is the purpose of <code>@Override</code> keyword, because if I omit it, it
  still works the same.  </li>
  <li>If I don't implement the abstract method, I get a compilation error. So what is the difference from implementing an interface?  </li>
  <li>Also, I can implement <code>method2()</code> in B as well. Then the output changes to what is use in B. Isn't this also overriding the parent class method? Then what is the purpose of explicitly defining a method as <em>abstract</em> in Class A?</li>
  </ul>