c# Abstration - C# Abstract


Abstract Class
An abstract class is a special type of class which acts as a base of other classes and cannot be instantiated. The implementation logic of an abstract class is provided by its derived classes. To make a class abstract, the “abstract” modifier is used which means some missing implementation needs to be implemented in the class derived from it. It contains both abstract and non-abstract members.

Example of Abstract Class:-

using System;

namespace AbstractClassExampleNamespace
{
    abstract class AbstractClassExampleClass
    {
        public void methodwithDefination()
        {
            Console.WriteLine("methodwithDefination Method: This is the method of Abstract Class with Defination");
        }
        public abstract void methodWithoutDefination();
    }

    class TestingClass : AbstractClassExampleClass
    {
        public override void methodWithoutDefination()
        {
            Console.WriteLine("methodWithoutDefination method: this is second method of interface without defination inside interface ");
        }

        public void TestingClassOwnMethod()
        {
            Console.WriteLine("TestingClassOwnMethod Method: This is another method of testing class");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            TestingClass objTestingCls = new TestingClass();
            objTestingCls.methodwithDefination();
            objTestingCls.methodWithoutDefination();
            objTestingCls.TestingClassOwnMethod();
            Console.ReadKey();
        }
    }
}