June 17, 2017

Sreekanth B

Write a C# Program to Illustrate Hierarchical Inheritance


Write a C# Program to Illustrate Hierarchical Inheritance:

This C# Program Illustrates Hierarchical Inheritance. Here Single parent and multiple child and when more than one derived class are created from single base class is called C# Hierarchical Inheritance.

Here is code of the C# Program to Illustrate Hierarchical Inheritance. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

ANS:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            Principal g = new Principal();
            g.Monitor();
            Teacher d = new Teacher();
            d.Monitor();
            d.Teach();
            Student s = new Student();
            s.Monitor();
            s.Learn();
            Console.ReadKey();
        }
        class Principal
        {
            public void Monitor()
            {
                Console.WriteLine("Monitor");
            }
        }
        class Teacher : Principal
        {
            public void Teach()
            {
                Console.WriteLine("Teach");
            }
        }
        class Student : Principal
        {
            public void Learn()
            {
                Console.WriteLine("Learn");
            }
        }
    }
}

Output:

Monitor
Monitor
Teach
Monitor
Learn


Subscribe to get more Posts :