Difference between Abstract Class and Interface in Java

Let us see what are the differences between Abstract Class and Interface in java. I listed out some of the major differences in the following table.


Abstract Class

Interface
1
Abstract class is a class which contains one or more abstract methods, which has to be implemented by sub classes.
A Java Interface can contain only method declarations and does not contain their implementation.
2
Abstract class has the constructor.
A Java Interface does not have the constructor.
3
Abstract classes can have a partial implementation, protected parts, static methods etc.
A Java Interfaces are limited to public methods and constants with no implementation.
4
Abstract class should be extended using keyword “extends”.
A Java interface should be implemented using keyword “implements”.
5

A class may extend only one abstract class.
A Class may implement several interfaces.
6
Abstract class permits accessibility modifier (Public/Private/internal).
Interface doesn’t permit accessibility modifier
7
Abstract classes are fast.

Interfaces are slow as it requires extra indirection to find corresponding method in the actual class.
8
An abstract class may contain complete or incomplete methods.

Interfaces can contain only the signature of a method but no body.
9
Abstract classes are useful in a situation when some general methods should be implemented and specialization behavior should be implemented by subclasses.
Interfaces are useful in a situation when all its properties need to be implemented by subclasses
10
Abstract scope is up to derived class.

Interface scope is up to any level of its inheritance chain.
11
Abstract class can have instance variables.
All variables in an Interface are by default - public static final
12
Example:
abstract class A
{
   abstract void display();
   public void add()
    {
      // Do addition stuff
    }
}

class B extends A
{
   void display()
   {
        // Do display stuff
   }
}

Example:
interface A
{
    void display();
    void add();
}
class B implements A
{
      void display()
   {
        // Do display stuff
   }
      void add()
   {
        // Do addition stuff
   }
}