Difference between abstract class and interface
Answer Posted / mohammad mousa fanasheh
Multiple inheritance:
interface :A class may inherit several interfaces.
Subtract: 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.
Access Modfiers:
An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public
An abstract class can contain access modifiers for the subs, functions, properties
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.
Speed:
Interface Requires more time to find the actual method in the corresponding classes.
abstract class Faster
Adding functionality (Versioning):
In interface .. If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.
In abstract class ..If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and Constants:
No fields can be defined in interfaces
An abstract class can have fields and constrants defined
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is one way operation?
How to improve the cache performance? : Dot net architecture
What is the difference between absolute expiration and sliding-time expiration?
inprocess vs out process session state : Dot net architecture
4. Wcf- what Asych and Sych call and how that works
Explain Intermediate Language?
What is .net mobile input validation. : Microsoft dot net mobile
how to create applications by using Visual Studio 2012?
What is a managed code is dim fs as filestreamobject is a managed code? : .NET Architecture
12. Types of polymorphisem[Run and Design Exp.]
how to delete the record using data reader
What is Object Caching in Visual Studio 2010?
Explain different pipelining hazards and how are they eliminated? : .NET Architecture
Explain hard disk? : Dot net architecture
Xmlserializer is throwing a generic "there was an error reflecting myclass" error. How do I find out what the problem is?