C# Program to Implement Hierarchical Inheritance Using the Abstract Class

Everyone has every option I have C# Program to Implement Hierarchical Inheritance Using the Abstract Class I have the option to write this article. I am writing this article to resolve your doubts. We ask that you understand this article well.

C# Program to Implement Hierarchical Inheritance Using the Abstract Class

C# Program to Implement Hierarchical Inheritance Using the Abstract Class

//C# program to demonstrate abstract class 
//for hierarchical inheritance.

using System;

abstract class Abs
{
    //Method Declaration
    public abstract void Method1();
}

class Sample1 : Abs
{
    //Method definition
    public override void Method1()
    {
        Console.WriteLine("Method1() called");
    }
}

class Sample2 : Sample1
{
    //Method definition
    public void Method2()
    {
        Console.WriteLine("Method2() called");
    }
}

class Sample3 : Sample1
{
    //Method definition
    public void Method3()
    {
        Console.WriteLine("Method3() called");
    }
}

class Program
{
    public static void Main(String[] args)
    {
        Sample2 S2 = new Sample2();
        Sample3 S3 = new Sample3();

        S2.Method1();
        S2.Method2();

        S3.Method1();
        S3.Method3();
    }
}
Method1() called
Method2() called
Method1() called
Method3() called
Press any key to continue . . .

Final Words

We hope the C# Program to Implement Hierarchical Inheritance Using the Abstract Class article fills your doubts. And let us know if you have any doubts. We resolve your doubts Thank you.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment