| |
|
difference in between abstrct classes and interfaces Question Posted on 24 Nov 2011 Home >> OOPS >> oops questions >> difference in between abstrct classes and interfaces |
(1)Multiple inheritance
Interface is not a class but a class may inherit several interfaces.
A class may inherit only one abstract class.
(2)Default implementation
Interface not provide any code that is default
abstract class provide default code and/or just the details that have to be overridden.
(3)Fast
Interface eequires more time to find the actual method in the corresponding classes.
It is very fast in abstract class
(4)Access Modfiers
Interface doesnot have access modifiers for its subs, functions, properties etc everything is assumed as public
Abstract class can contain access modifiers for the subs, functions, properties
(5)Declartion of Fields
Interface cannot defined and fields
Abstract class can have fields and constrants declartion
(6)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.
(7)Homogeneity
Interface is suitable where various implementations only share method signatures
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
(8)New Method
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.
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. | |
|
|
|
|