Difference between Abstract Class and Interface

Abstract class and interface have similarities. However both are quite different in behavior and usages. This made me to 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.
    Note: Java 8 onwards it is changed after the introduction of default method. Also, static methods are also got introduced in interfaces like Comparator.comparing(...).
  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.
    Note: This is applicable version 7 and below. Java now allows default and static methods in interfaces that have the concrete implementation.
  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.

2 comments

Write comments
de
AUTHOR
Wed Sep 11, 12:05:00 PM GMT+5:30 delete

Great explanation.The difference is, In abstract class you can define the method and in subclass you should override it.But incase of interface you can't define the method you can only declare and you should override it in subclass.

sankar
java course in chennai

Reply
avatar
de
AUTHOR
Wed Sep 11, 12:22:00 PM GMT+5:30 delete

Great Explanation.The difference is, In abstract class you can define the method and in subclass you should override it.But incase of interface you can't define the method you can only declare and you should override it in subclass.

prathap
java course in chennai

Reply
avatar