Difference Between Abstract Classes and Interfaces
Abstract Classes Vs Interfaces
- Abstract Classes can have concrete methods while Interfaces can have only abstract methods.
- Abstract Classes can have fields and constants while Interfaces can have only constants(public static).
- Abstract Classes can have Private and Protected members while Interfaces can have only Public.
- A Class can extend from only one Abstract Class but can implement any number of Interfaces
- Abstract Classes can provide a default implementation while Interfaces can only provide the signature
- Abstract Classes are used for defining the core functionality of a class while Interfaces are used for defining the peripheral functions of a class.
- Abstract Classes are faster than Interfaces as Interfaces require time to find the actual method in the corresponding class.
- Adding/Modifying an Interface will involve searching every implementation and modifying it while this can be avoided for Abstract Classes by providing a default behavior.
No comments:
Post a Comment