Total Page Preview:   000000019921

What is the difference between Interface and Abstract class in English and Hindi

 

Introduction :

In this post I am going to explain the difference between Abstract Class and Interface with examples in C#.

In Hindi

"Es post me main Abstract Class and Interface me difference batane ja raha hu"

Abstract Class :

An Abstract class is an incomplete class or special class we can't instantiate. We can use an Abstract class as a Base Class. An Abstract method must be implemented in the non-Abstract class using the override keyword. After overriding the abstract method is in the non-Abstract class. We can derive this class in another class and again we can override the same abstract method with it.

In Hindi

"Ek Abstract class ek incomplete class or special class hai jiska hum log object nahi bana sakte. Hum log ek abstract class ko as a base class use kar sakte hai. Ek non-abstract class me override keyword ka use karke ek abstract method jarur implement hoga. Ek non-abstract class me ek abstract method use karne ke baad me hum log ush class ko ek dusri class me derive kar sakte hai aur fir se hum log ush class me wahi abstract method override kar sakte hai"

Interface :

An interface looks like a class, but has no implementation. The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by structs and classes, that must provide an implementation for each interface member declared.


In Hindi

"Ek interface ek class ki tarah dikhai deta hai lekin uska koi implementation nahi hota hai. Sirf yah chij hai ki yah events, indexes, methods and/or properties ka declarations rakhta hai. Yah baat hai ki interfaces sirf declarations provide karta hai kyuki ye structs aur classes se inherit hota hai jo har interface member jo declared hai uska implementation provide karta hai"


Difference Between Interface and Abstract Class


Feature Interface Abstract class
Multiple inheritance

Interface support multiple inheritance

In Hindi

"Interface multiple inheritance ko support karta hai"

Abstract class does not support multiple inheritance

In Hindi

"Abstract class multiple inheritance ko support nahi karta hai"

Default implementation

An interface cannot provide any code, just the signature.

In Hindi

"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

In Hindi

"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

In Hindi

"Interface ke member static nahi ho sakte"

Only Complete Member of abstract class can be Static

In Hindi

"Abstract class ke sirf complete member hi static ho sakte hai"

Constructors

Interface doesn't contains Constructors

In Hindi

"Interface constructors ko nahi rakhta"

Abstract class contains Constructors

In Hindi

"Abstract class constructors ko rakhta hai"

Speed

Interface doesn't contains Constructors

In Hindi

"Interface constructors ko nahi rakhta"

Abstract class contains Constructors

In Hindi

"Abstract class constructors ko rakhta hai"

Fields and Constants

No fields can be defined in interfaces

In Hindi

"Interfaces me koi field define nahi ho sakti"

An abstract class can have fields and constraints defined

In Hindi

"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

In Hindi

"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

In Hindi

"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.

In Hindi

"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.

In Hindi

"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.

In Hindi

"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.

In Hindi

"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.

In Hindi

"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..

In Hindi

"ek abstract class ek class ki core identity ko define karta hai aur yah same type ke objects ke liye use kiya jata hai"


Interface Example :

Exapmle for Interface

Interface Example:

namespace RAndDInConsole
{
public class Program
{
static void Main(string[]args)
{
ChildClass obj = new ChildClass();// Create intence to ChildClass
Console. WriteLine( "Sum is :" + obj.Sum(33, 34));
Console.WriteLine( "Substraction is :" + obj.Substraction(50,34));
Console.ReadLine();
}

}

//There we can use multiple inheritance but abstract class we can't use multiple inheritance
public class ChildClass : IAddition, ISubstraction
{
public double Sum( int num1, int num2)
{
return (num1 + num2);
}
public double Substraction( int num1, int num2)
{
return (num1 - num2);
}

}
// Interface create for addition
public interface IAddition
{
double Sum( int num1, int num2);
}
// Interface create for Substraction
public interface ISubstraction
{
double Substraction( int num1, int num2);

}
}

Abstract Class Example :

Exapmle for Interface

Abstract Class Example:

namespace RAndDInConsole
{
public class Program
{
static void Main(string[]args)
{
ChildClass obj = new ChildClass();// Create intence to ChildClass
Console. WriteLine( "Sum is :" + obj.Sum(33, 34));
Console.WriteLine( "Substraction is:" + obj.Substraction(50,34));
Console.WriteLine( "Multiplication is :" + obj.Multiplication("33", "34"));
Console.ReadLine();
}

}

public class ChildClass : Addition //There we can not use multiple inheritance becaouse abstract class does not support it.
{
//Abstract method will be override here
public override double Sum(int num1, int num2)
{
return (num1 + num2);
}
//Abstract method will be override here
public override double Substraction(int num1, int num2)
{
return (num1 - num2);
}
}
public abstract class Addition
{
//We can use construction in abstract class but can't in interface.
public Addition ()
{
//statements
}
//This is abstract methods
public abstract double Sum(int num1, int num2);
public abstract double Substraction(int num1, int num2);

//There we can impement an other method but can't impement in interface.
public double Multiplication(string num1, string num2)
{
double number1, number2;
number1 = Convert.ToDouble(num1);
number2 = Convert.ToDouble(num2);
return (number1 * number2);
}

}

}
 
 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments

Pankaj Singh
09-Mar-2016
nice article its too good for understanding pupose in hindi and english both languages.
Brijesh Kumar
09-Mar-2016
Thank Pankaj.
MANAN
15-Jun-2017
Thanks , For Sharing This Articles Keep sharing and have a great time blogging. Superb Idea.
MANAN
15-Jun-2017
Thanks , For Sharing This Articles Keep sharing and have a great time blogging. Superb Idea.
Soniya Manjani
01-Oct-2016
This is very nice article and easy to understand.

                           
                           

                           

                           

Recent Posts

Facebook User: