+3

Interface or abstract class

When you are working on a project and you are confused between implementing interface or working with abstract classes, what is preferably used and why?

4/5/2020 3:47:49 PM

Dhafer ABDELKADER

1 Answer

New Answer

+4

Depends on what level of abstraction you want to achieve. Abstract classes can have both abstract and non-abstract methods which can contain common implementation for all your subclasses. Interface on the other hand is useful when you want all of your implementing classes to have their own implementation of the abstract method declared in the interface. Interface also have default and static methods which can have the method implementation within the interface. So there isn't much of a difference but it is advised to use abstract classes in most cases.