Abstract class
An abstract class is a class where we can create abstract methods as well as concrete methods. An abstract class & abstract method should be declared using abstract keywords. An abstract class can have any number of abstract and non-abstract methods. We can't create instances of an abstract class but we can create instances of its subclasses.
- We can't create objects of abstract class
- The abstract method must have without definition.
- An abstract class can have a concrete method as well.
- An abstract class can have without an abstract method.
- An abstract class can never be sealed or static.
- A concrete class can not inherit more than one abstract class. It means multiple inheritances is not possible in abstract classes.
- It contains a constructor.
- It can contain access modifiers.
Interface
An interface is similar to an abstract class but by default all methods are abstract. It means that it can't have concrete methods, It is just like method signature without implementation. We use the interface keyword to define an interface. We can't use access modifiers because by default is abstract.
- We can't create an object of interface
- Interface only contain method signature without definition.
- We can't use access modifiers in the interface.
- A concrete class can inherit more than one interface. It means multiple inheritances are possible in the interface.
When to use Abstract class
If we know about implementation not completely but partially then we should go for abstract class. For example some common functionality like if we have a mobile phone of Samsung and iPhone. In mobile phones some common functionality is CALL and SMS but non-common functionality is color, screen size, and operating system. So here we can create class MobilePhone then can create a concrete method for CALL, SMS, and abstract method for color, screen size, and operating system. Let's begin with an example.
class Program
{
static void Main(string[] args)
{
MobilePhone samsung = new Samsung();
samsung.Call();
samsung.Sms();
samsung.Color();
samsung.ScreenSize();
samsung.OperatingSystem();
Console.ReadLine();
}
}
public abstract class MobilePhone
{
public void Call()
{
Console.WriteLine("Concrete Method: You can make a call");
}
public void Sms()
{
Console.WriteLine("Concrete Method: You can send a message");
}
public abstract void Color();
public abstract void ScreenSize();
public abstract void OperatingSystem();
}
public class Samsung : MobilePhone
{
public override void Color()
{
Console.WriteLine("Abstract method: This samsung mobile color is white");
}
public override void ScreenSize()
{
Console.WriteLine("Abstract method: This samsung mobile screen size is 5 inch");
}
public override void OperatingSystem()
{
Console.WriteLine("Abstract method: This samsung mobile android operating system");
}
}

The above example is for Samsung mobile and the below example for iPhone.





Join the conversation! Your thoughts help the community grow.