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


Please Help Members By Posting Answers For Below Questions

Explain the difference between l1 and l2 cache? : Dot net architecture

737


What is .net mobile lists. Explain with an example? : Microsoft dot net mobile

674


What is the problem with .net generics?

811


Define a managed code? : Dot net architecture

679


What is the use of CLR in .NET?

767


What is the difference between machine config vs. Web config : Dot net architecture

701


Explain how does .net mobile work? : Microsoft dot net mobile

655


Can you explain update progress control?

696


Differences between VS 2005, 2008 and 2010 ?

766


Can I customise the trace output?

830


Can you explain control extenders?

690


Explain difference between inprocess vs out process session state? : .NET Architecture

711


Explain different pipelining hazards and how are they eliminated? : .NET Architecture

707


IS IT Possible to inherit the AJAX page from child class which(child) is inherit from page class.Because i should apply some security in child class

1734


How can I create a application?

687