Hi,
What is the difference between abstract class and interface ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Mar 17, 2012, 12:33 AM
Please also refer Our recommended articles.
Thanks
SenthilkumarPosted Mar 16, 2012, 11:52 PM
The abstract class can have access modifiers (internal and public). The interface will have the public as default access modifier.
The interface cannot have implementation of methods. But the abstract class can have non abstract methods.
The interface can be base class to implement the multiple inheritance. But the abstract classes cannot be base class to implement the multiple inheritance
You can see the difference in table format.
Features Interfaces abstract class
Multiple inheritance
A class may inherit several interfaces.
A class may inherit only one abstract class.
Default implementation
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or just the details that have to be overridden.
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.
An abstract class defines the core identity of a class and there it is used for objects of the same type.
Homogeneity
If various implementations only share method signatures then it is better to use Interfaces.
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Speed
Requires more time to find the actual method in the corresponding classes.
Fast