|
Abstract Class
|
Interface
|
Definition |
An Abstract Class is always used to serve as a base class as it can’t be instantiated. |
An Interface is one type of template having only signature of methods. |
Type of Methods |
An Abstract class contains abstract methods and non-abstract (concrete) methods. |
An Interface contains all abstract methods i.e. all methods have to be abstract. |
Default Behavior
|
By Abstract class you can provide default implementation to any method. |
By interface you cannot provide default implementation of any method as it only contains signature of methods. |
Multiple Inheritance |
Any Class can inherit only one Abstract Class so no support for multiple inheritance. |
Any Class can’t inherit more than one class but it can implement more than one interface. |
Object
|
You can not create the object of Abstract Class so it must be inherited by other class. |
Generally we don’t create the objects of interface we implement the interface in required class. |
Variable |
You can define & use any variable in abstract class . |
An Interface does not allow declaration & use of variable as interface does not contain fields. |
Constructor |
An abstract class can have a constructor. |
An interface can not have a constructor. |
Inheritance |
If any class already have a base class, it can not inherit abstract class. |
Though class have a base class, it can implement any number of interfaces. |
Access Modifiers |
An Abstract Class allows to use all access modifiers for the declaration of its members. |
An interface does not allow to use any access modifiers for its member declaration and uses public access modifier as default. |
Speed |
To access an abstract class is fast than interface. |
Interface is slower in compare to abstract class. |