Proper understanding about Interface and Abstract classes


It's been long time, we hear about difference between Interface and Abstract classes and what are the advantage of each over other and in which circumstances we may need to use either interface or abstract...

Without any implementation, both looks to be same. But still there are lot of difference between Interface and Abstract class.

First of all, Abstract class is a special kind of class which cannot be instantiated and it can only be sub-classed.

Interface is not a class and so it is not having any implementation, it is having only signature.
Both interface and abstract class - are a contract between the classes which is consumed to use certain methods and its arguments defined in it.

All the methods which we declared in interface need to be implemented in classes which the interface is used.
Inside abstract class we can write non-abstract methods so, which can be excluded in the classes where it is inherited.
A class can implement multiple interfaces, where a classe can inherit only one abstract class, so multiple inheritance is not possible with abstract class.

An abstract class without any implementation looks like an interface.

Comments