Abstract Class in C# Tutorial with Example

Abstract Class in C# Tutorial with Example

Today, We want to share with you Abstract Class in C# Tutorial with Example.
In this post we will show you All about abstract classes in C#, hear for Understanding C Sharp Abstract Classes – C# Abstract Keyword we will give you demo and example for implement.In this post, we will learn about C# Abstract Classes Tutorial with Example with an example.

Introduction to Abstract Class in C#

The Abstract keyword is used to make Abstract Class in C#. Abstract classes are not complete so we can not create an instance of this classes. An Abstract class can only be a base class of some another class.

Also Read :  Angular 6 HTTP Get Method with Example

This type of class can have both abstract and non-abstract methods inside it. Abstract members do not have any implementation body part in the abstract class, but it has to be provided in its derived class.

Example of Abstract Class in C#

using System;

namespace AbstractDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            MakeCalculation obj = new MakeCalculation();

            Console.WriteLine("Sum of 3 + 8 = " + obj.AddNumber(3, 8)); // Calling and displaying result of abstract class methods.

            Console.WriteLine("Multiplication of 3 * 8 = " + obj.MultiplyNumber(3, 8));

            Console.Read();
        }
    }

    abstract class Calculation
    {
        public abstract int AddNumber(int a, int b); // Method with only declaration i.e. Abstract Methods

        public int MultiplyNumber(int a, int b) // Method with implementation details 
        {
            return a * b;
        }
    }

    class MakeCalculation : Calculation // Inheriting abstract class.
    {
        public override int AddNumber(int a, int b) // Providing implementation details for abstract methods.
        {
            return a + b;
        }       
    }
}

Read :

Also Read :  C# nested while loops and multiple conditions

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about C# Abstract Classes Tutorial with Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Gondaliya Jaydeep

Hi, I’m Jaydeep Gondaliya, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]

Leave a Reply

  • (will not be published)