I found that lots of people our there are confused between abstract and interface, including me :-). So i formulated this simple table which list most of the differences between them.
| Index | Abstract | Interface |
|---|---|---|
| 1 | Cannot instantiate(not possible to create object of an abstract class) | Cannot instantiate. (not possible to create object of an interface) |
| 2 | Can have method implementations inside the class | Cannot have method implementations, only method signatures |
| 3 | Can have access specifiers | Cannot have access specifiers (like public,private,protected,internal etc.) |
| 4 | Can inherit from a class and one or more interfaces | Can only inherit from another interface |
| 5 | Can contain data fields |
Cannot contain data fields For ex: public interface myInterface { int myVals; //not possible } |
| 6 |
Can contain property implementations.
|
Cannot contain property implementations. For ex: public interface myInterface string myProp1 |
| 7 | Can contain constructors and destructors. | Cannot contain constructors and destructors. |
| 8 | Structure cannot inhert an abstract class. | Structure can inherit an interface. |
| 9 | Does not support multiple inheritance. | Supports multiple inheritence. |
| 10 | Derived class doesn’t need to implement all base class methods. | Derived class needs to implement all base class methods. |
Please refer to it. I hope it was helpful. Please point out if there is been an error. Happy Coding!!!!
Discover more from Code, Cloud & Context
Subscribe to get the latest posts sent to your email.
1 Comment.