Feature |
Interface |
Abstract class |
Multiple inheritance |
Interface support multiple inheritance
"Interface multiple inheritance ko support karta hai"
|
Abstract class does not support multiple inheritance
"Abstract class multiple inheritance ko support nahi karta hai"
|
Default implementation |
An interface cannot provide any code, just the signature.
"Ek interface koi bhi code provide nahi kar sakta hai, sirf signature provide karta hai"
|
An abstract class can provide complete, default code and/or just the details that have to be overridden
"Ek abstract class complete, default code and/or sirf details jo overridden hai provide kar sakta hai"
|
Member Static |
Member of interface cannot be Static
"Interface ke member static nahi ho sakte"
|
Only Complete Member of abstract class can be Static
"Abstract class ke sirf complete member hi static ho sakte hai"
|
Constructors |
Interface doesn't contains Constructors
"Interface constructors ko nahi rakhta"
|
Abstract class contains Constructors
"Abstract class constructors ko rakhta hai"
|
Speed |
Interface doesn't contains Constructors
"Interface constructors ko nahi rakhta"
|
Abstract class contains Constructors
"Abstract class constructors ko rakhta hai"
|
Fields and Constants |
No fields can be defined in interfaces
"Interfaces me koi field define nahi ho sakti"
|
An abstract class can have fields and constraints defined
"Ek abstract class me fields and constraints define ho sakte hai"
|
Access Modifiers |
An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public
"Ek interface me subs, functions, properties etc ke liye access modifiers nahi ho sakte"
|
An abstract class can contain access modifiers for the subs, functions, properties
"Ek abstract class me subs, functions, properties ke liye access modifiers ho sakte hai"
|
Homogeneity |
If various implementations only share method signatures then it is better to use Interfaces.
"agar bahut implementations sirf share method signatures ke liye hai tab interfaces ka use bahut hi achchha hai"
|
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
"agar bahut implementations same kind ke hai aur common behaviour or status ka use kar rahe hai tab abstract class ka use bahut hi achchha hai"
|
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.
"agar hum log ek naya method ek interface me jodte hai tab hum logo ko interfaces me kiye huye sabhi implementations ko track down karna hoga aur naya method ka implementation define karna hoga"
|
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.
"agar hum log ek naya method ek abstract class me jodte hai tab hum logo ke pas ek option hota hai default implementation provide karna aur tab uske baad sabhi pahle se bane huye code sahi kaam kar sakte hai"
|
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.
"ek class ki peripheral abilities ko define karne ke liye interfaces ka use kiya jata hai. Dusre sabdo me kaha jaye to ek imovable interface se insan aur gadi dono ko inherit kar sakte hai"
|
An abstract class defines the core identity of a class and there it is used for objects of the same type..
"ek abstract class ek class ki core identity ko define karta hai aur yah same type ke objects ke liye use kiya jata hai"
|