Difference between Abstract Class and Interface

There were many people who asks me what is the difference between an abstract class and interface. This made me writing this article. I presume, you have the basic knowledge of Abstract class and Interface with respect to Java.

  1. Fundamental difference between these two with respect to Object Oriented Programming concepts lies in relationships. Interface represents a weak "is-a" (is a kind of) relationship, indicates that object possesses a particular property for example String class implements the Comparable interface; whereas abstract class represents a strong "is-a" relationship that clearly describes parent child relationship for example a Customer is a person.
  2. In interface, by default all members (variables) are constants aka public static final where as in Abstract Class there is no restriction with respect to member visibility.
  3. In Interface, by default all methods are public abstract whereas in Abstract Class there is no restrictions
  4. Interface does not contain any constructor whereas though abstract classes also can not be instantiated by new operator, constructor are invoked by subclasses through constructor chaining.
  5. Multiple interfaces can be implemented at once which is not the case with Abstract Class as Java does not support multiple inheritance.
  6. Interface only provides the method signatures; whereas Abstract Classes may provide the concrete implementation of the methods.
  7. Interface does not allow implementation class to modify the visibility of the methods; where as implementation of abstract class may have less or same restrictive visibility for abstract methods.

Myth: Many suggested that there is performance related difference between these two. Abstract class are better than interfaces in terms of performance. If JVM has JIT, then there is no performance related difference between these two. Check out more on Android Performance Tips

Do you enjoy this article? please help spread the word. And if you don't, then let me know how I can improve it.


Write comments