Users Online

· Guests Online: 106

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate Hierarchical Inheritance

C# Program to Demonstrate Hierarchical Inheritance

 

 

 

This is a C# Program to illustrate hierarchical inheritance.

Problem Description

This C# Program Illustrates Hierarchical Inheritance.

Problem Solution

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

Program/Source Code

Here is source 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.

/*
 *  C# Program to Illustrate Hierarchical Inheritance
 */
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");
            }
        }
    }
}
Program Explanation

This C# program is used to illustrate hierarchical inheritance. We have created two classes Principal and Teacher. Using the object variable ‘g’ of Principal class perform the Monitor() procedure. Using the object variable ‘d’ of Teacher class perform the Monitor() and Teach() procedure.

 

Finally using ‘s’ object variable perform the Monitor() and Learn() procedure. Here Single parent and multiple child and when more than one derived class are created from single base class are called C# Hierarchical Inheritance.

Runtime Test Cases
 
Monitor
Monitor
Teach
Monitor
Learn

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.02 seconds
10,836,865 unique visits