Site icon Technology and Trends

Difference between Abstract Class and Interfaces in Java

An abstract class is a java class that has one or more abstract methods (nobody). It cannot be instantiated and defines an interface that has to be implemented by all its subclasses.

Abstract classes vs. Interfaces

The below table shows the difference between abstract classes and Interfaces in Java.

FieldAbstract ClassInterface
Method TypeAbstract ,Non-Abstract ,default and StaticAbstract Method
Final Variablefinal and non-final variableVariables final by Default
Variable Typefinal, non-final, static and non-static variablesonly static and final variables
Access ModifiersIt can have class members
like private, protected, etc.
All the Members of a Java interface are public by default
Keywordsabstract class can be
extended using keyword “extends”.
A Java interface can be implemented using keyword “implements”
ImplementationAn abstract class can provide
the implementation of the interface.
Interface can’t provide the implementation of an abstract class.
Multiple Implementation An abstract class can
extend another Java class and implement multiple Java interfaces
An interface can extend another Java interface only .
Exit mobile version