Difference Between an Interface and an Abstract class?
Interface |
Abstract class |
---|---|
An Interface is used to define methods (have no Body) but not for the implementation. |
An Interface abstract class can be used to implement the Methods. |
An Interface allows us to use multiple inheritance. |
An Abstract Classes does not allows us to use multiple inheritance. |
Interfaces are slow. |
Abstract classes are fast. |
When we have similar classes that will share code use an abstract class. |
When we have classes that are nothing to do with one another but share some aspect that they do not share a common ancestor then use an interface. |
An Interface cannot implement methods. |
An abstract class can implement methods. |
An Interface can only inherit from another Interface. |
An abstract class can inherit from a class and one or more interfaces |
An Interface cannot contain fields. |
An abstract class can contain fields. |
An Interface can contain property definitions. |
An abstract class can implement a property. |
An Interface cannot contain constructors or destructors. |
An abstract class can contain constructors or destructors. |
An Interface can be inherited from by structures. |
An abstract class cannot be inherited from by structures. |
An Interface can support multiple inheritances. |
An abstract class cannot support multiple inheritances. |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.