What is the difference between Abstract and Interface?
Answer Posted / code project main se teepa hai
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.
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
Adding functionality (Versioning)
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.
Fields and Constants No fields can be defined in
interfaces An abstract class can have fields and constrants
defined
Is This Answer Correct ? | 8 Yes | 1 No |
Post New Answer View All Answers
What is different between Boxing and Unboxing?
Does c# support c type macros?
What is main thread in c#?
Are value types sealed?
Can bool be null c#?
What is difference between Enum and Struct?
What are c# i/o classes? What are the commonly used i/o classes?
Distinguish between a class and struct?
Explain about Oops concept
Explain the difference between Response.Write () and Response.Output.Write ().
What will a loop recorder show?
What is a console in c#?
If the interface in c# only contains the declaration of the methods and we need to define those methods in the class, then why we use the interface?
Is string primitive?
What standard types does c# use?