C# program to show multiple inheritance using class and interface

Category > CSHARP || Published on : Saturday, November 14, 2020 || Views: 39 || show multiple inheritance using class and interface


Here Pawan Kumar will explain how to show multiple inheritance using class and interface

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication19
{
    class A
    {
        public virtual void Show()
        {
            Console.WriteLine("Show A1");
        }
        public void Disp() { }
    }
    interface Z
    {    void Call();
    }
    class B : A, Z
    {
        public override void Show()
        {
            Console.WriteLine("Show B1");
        }
        public void Call()
        {
            Console.WriteLine("Call B1");
        }
    }
      class Demo
      {
        static void Main(string[] args)
        {
            B b = new B();
            Console.WriteLine("----B1---");
            b.Show(); // will call show() of B class
            b.Call(); // will call call() of B class
            A a = b;
            Console.WriteLine("---(A=B)--");
            a.Show(); // will call show() of B class
            Console.ReadLine();
        }
    }
}