Difference Between Abstract Class and Interface


Main Difference

The main difference between abstract class and interface is that the procedures of Java interface are essentially abstract and cannot have applications. So broadly stating, interface is actually a contract and when we talk about interface, it applies that the methods do not have a body, it is just a pattern. While abstract classes are basically the classes which are expensive to use. Abstract classes and interface is a whole different concept, these are two different things but at times their implementations are quite similar.

What is Abstract Class?

An abstract class is not completely implied by the programmer. An abstract class may have one or more abstract methods. They are useful for modelling a class grouping or ranking and while while this is being carried out, the programmer get the idea of what has to be build after seeing the requirements. Abstract class cannot be relied upon completely because it lacks some parts. The main point behind this argument is, the abstract class is strictly object oriented, although it has a method heading but no body. When we talk about abstract classes, there is a strong connection between two classes, because theses classes tend to gain or inherit from one another.


What is Interface?

When we talk about interface, on the contrary then the relation or communication between interface itself and the class implying the interface is not as strong as it is in abstract classes. A Java class can implement many interfaces but can inherit from a single abstract class. So, that means that when you want to imply many interactions at one time then interface is your thing. Apart from this whole scenario, even when you do not want the API to change for a while then interface is the best option for you. Interface is actually the contract between two different objects. To cut it short, interface revolves around the functionality.


Key Differences

  1. An abstract class is object orientated while interface is function oriented.
  2. When you want API to stay constant for a while then you choose interface over abstract class.
  3. Multiple inheritances could be gained by implying multiple interfaces. While in abstract class, you cannot get multiple inheritances.
  4. If you have a vibe that you in future you would need to add methods in your work then abstract class is opted, not interface.
  5. Abstract class gives a common base class application but nothing of such happens in interface.
  6. In interface, all the methods you implement are public but in abstract class you can also apply some non-public methods.
  7. Constructors are not there in interface but they do occur in abstract class.
  8. Complete member of abstract class could be static but not of interface.
Harlon Moss

Harlon currently works as a quality moderator and content writer for Difference Wiki. He graduated from the University of California in 2010 with a degree in Computer Science. Follow him on Twitter @HarlonMoss