Abstract class:
An Abstract class without any implementation just looks like an Interface; however there are lot of differences than similarities between an Abstract class and an Interface.
- We cannot make instance of abstract class.
- An abstract class is only to be sub-classed (inherited from).
- In other words, it only allows other classes to inherit from it but cannot be instantiated.
Interface concept:
An interface is not a class.
An interface has no implementation; it only has the signature.
It just the definition of the methods without the body.
Similarity between Abstract class and Interface:
They act as a contract that is used to define hierarchies for all their subclasses.
Different:
A class can implement more than one interface but can only inherit from one abstract class.
Since C# doesn't support multiple inheritance, interfaces are used to implement multiple inheritance.
Sample Code Download: AbstractBase_Vs_Interface.zip
No comments:
Post a Comment