title: Abstract class vs Interface in Java
body: <p>I was asked a question, I wanted to get my answer reviewed here.</p>
  
  <p><strong>Q:</strong> In which scenario it is more appropriate to extend an abstract class rather than implementing the interface(s)?</p>
  
  <p><strong>A:</strong> If we are using template method design pattern.</p>
  
  <p>Am I correct ?</p>
  
  <p>I am sorry if I was not able to state the question clearly.<br>
  I know the basic difference between abstract class and interface.</p>
  
  <p>1) use abstract class when the requirement is such that we need to implement the same functionality in every subclass for a specific operation (implement the method) and different functionality for some other operations (only method signatures) </p>
  
  <p>2) use interface if you need to put the signature to be same (and implementation different) so that you can comply with interface implementation  </p>
  
  <p>3) we can extend max of one abstract class, but can implement more than one interface  </p>
  
  <p><strong>Reiterating the question:</strong> Are there any other scenarios, besides those mentioned above, where specifically we require to use abstract class (one is see is template method design pattern is conceptually based on this only)?</p>
  
  <p>Interface vs. Abstract class</p>
  
  <p>Choosing between these two really depends on what you want to do, but luckily for us, Erich Gamma can help us a bit.</p>
  
  <p>As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the <strong>freedom to add new methods later</strong>. – Erich Gamma</p>
  
  <p>You <strong>can’t go and change an Interface without having to change a lot of other things</strong> in your code, so the only way to avoid this would be to create a whole new Interface, which might not always be a good thing.</p>
  
  <p><code>Abstract classes</code> should primarily be used for objects that are closely related. <code>Interfaces</code> are better at providing common functionality for unrelated classes.</p>