Introduction

Abstract classes are incomplete classes and you cannot instantiate objects from abstract class.

The child of abstract classes must complete them first and then they can redefine some of the methods by overriding.

If a class contains at least one incomplete/abstract method, the class itself is an abstract class.

The abstract method means that the method has the declaration or signature but no implementation.

Abstract members are virtual members without a default implementation.

Rule

A class that contains at least one abstract method must be marked as an abstract class.

The subclass must provide implementations or they will be again marked with the abstract keyword.

Demo

using System;

abstract class MyAbstractClass
{
    public abstract void ShowMe();
}
class MyConcreteClass : MyAbstractClass
{
    public override void ShowMe()
    {//from  w ww .j a  va  2 s. c  om
        Console.WriteLine("I am from a concrete class.");
        Console.WriteLine("My ShowMe() method body is complete.");
    }
}
class Program
{
    static void Main(string[] args)
    {
        //Error:Cannot create an instance of the abstract class
        // MyAbstractClass abstractOb=new MyAbstractClass();
        MyConcreteClass concreteOb = new MyConcreteClass();
        concreteOb.ShowMe();
    }
}

Result

Related Topic