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

deference between display and visibility property of CSS

1789


How does an appdomain get created?

555


What are the main Tools to develop .Net Application?

539


What is difference between .net and visual studio?

521


Difference between throw exception and rethrowing ?

1674






Explain a .net mobile example with details? : Microsoft dot net mobile

478


Explain the difference between primary & secondary storage device? : Dot net architecture

514


Define domestic architecture artifacts? : Dot net architecture

527


Explain write back and write through caches? : .NET Architecture

519


Explain element .net mobile with example? : Microsoft dot net mobile

503


State and explain about microsoft.net?

528


What is an interrupt? : .NET Architecture

477


what is sessions and cookies take one example simple way to understand

1857


Can you explain update progress control?

523


What happens when you try to update data in a dataset in .net while the record is already deleted in sql server as backend?

513