Abstract Class in C#

In this article we will discuss about what is abstract Class in C# and how it will be implemented in C#.
  • 3011

Any Class which is having at least one abstract method or member becomes an abstract Class. We cannot create the object of abstract Class that can only be inherited. A child Class which will be inheriting the abstract class is mandatory to define all the abstract member of base class. A derived Class should implement all the abstract member of the abstract Class otherwise it has to be declared as abstract class. If we will not declare a class as abstract which is having at least one abstract method, compiler will generate the error.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace absclass

{

    class Program

    {

        static void Main(string[] args)

        {

            cls obj = new cls();

            obj.show();

            obj.msg();

            Console.ReadLine();

        }

    }

    public abstract class student

    {

        public abstract void msg();

        public void show()

        {

            Console.WriteLine("This is show method");

        }

    }

    public class cls : student

    {

        public override void msg()

        {

            Console.WriteLine("This is msg method");

        }

    }

}

Output:

Image9.jpg

Further Readings
 
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.