Interface vs Abstract Class In JAVA

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. On the other hand, abstract class refers to the class that contains atleast one abstract method must be declared abstract.

Interfaces and abstract classes both implements polymorphic behavior and seem to be similar but they are different in the following ways:

Interface

 

Abstract Class 

An interface is purely abstract i.e. methods in an interface only have declarations no Implementations. Abstract class methods may or may not have any implementation.

 

A class implements an interface must implement all of the methods declared in the interface.

 

A class extending an abstract class need not implement any of the methods defined in the abstract class.

 

Interfaces can be implemented by unrelated classes. Abstract classes are used only where there is a IS-A relationship between the classes.

 

You can implement more than one interface. You cannot extend more than one abstract class.

 

User-defined exception can be defined within an interface itself. User-defined exception cannot be defined within the abstract class.

 

Members of an interface are public by default and cannot have any other access specifier. Members of an abstract class can have access modifiers.

 

Interface definition begins with a keyword interface. Abstract class definition begins with the keyword abstract followed by class definition.
All the variables in an interface are static, final and public by default. An abstract class can have instance variables.

 

Interface support multiple inheritance. Abstract class does not support multiple inheritance.

 

Interface can extend another interface. Abstract class can implement multiple interfaces and extend another class.

 

Interface cannot have constructors.

 

An abstract class can have constructors.

Also Read: Abstraction In JAVA