| Abstract | Interface |
| Abstract class having method declaration as well as method method definition. | Interface having method declaration only. |
| Abstract class are known as partial abstract class | Interface is known as fully abstract class |
| Abstract class features we have to inherit to the child class | Interface features we have to implement in the child classes. |
| Abstract class support access specifiers | Interface doesn't support access specifiers |
| We can write constructor in abstract class | we can't write constructor in interface |
More....
- The abstract class allows concrete methods (methods that have implementation) but interface doesn’t not.
- A class can inherit from only one class, but can implement any number of interfaces.
- Interface doesn’t allow variables/constants to be declared but abstract class allows for declaration of variables and constants
More...
Abstract Class vs. Interface
2. An abstract class can contain fields, constructors, or destructors and implement properties. An interface cannot contain fields, constructors, or destructors and it has only the property's signature but no implementation
3. An abstract class cannot support multiple inheritances, but an interface can support multiple inheritances. Thus a class may inherit several interfaces but only one abstract class.
4. A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.
5. Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.
6. Abstract classes are faster than interfaces.
No comments:
Post a Comment