What is the difference between an Interface and an Abstract class?

An Abstract Class can contain default Implementation, where as an Interface should not contain any implementation at all. An Interface should contain only definitions but no implementation. where as an abstract class can contain abstract and non-abstract methods. When a class inherits from an abstract, the derived class must implement all the abstract methods declared in the base class. an abstract class can inherit from another non-abstract class.

Comparision Table

Abstract classes
Interfaces
Abstract classes are used only when there is a “is-a” type of relationship between the classes.
Interfaces can be implemented by classes that are not related to one another.
You cannot extend more than one abstract class.
You can implement more than one interface.
Abstract class can implemented some methods also.
Interfaces can not implement methods.
With abstract classes, you are grabbing away each class’s individuality.
With Interfaces, you are merely extending each class’s functionality.

No comments:

Post a Comment

Please Provide your feedback here