C# Program to Demonstrate Multilevel Inheritance
Posted by Superadmin on August 13 2022 11:06:14

C# Program to Demonstrate Multilevel Inheritance

 

 

This is a C# Program to demonstrate multilevel inheritance.

Problem Description

This C# Program Demonstrates Multilevel Inheritance.

Problem Solution

Here when a derived class is created from another derived class, then that inheritance is called as multi level inheritance.

Program/Source Code

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

/*
 * C# Program to Demonstrate Multilevel Inheritance
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inherit
{
    class inheri : vehicle
    {
        public void Noise()
        {
            Console.WriteLine("All Vehicles Creates Noise !! ");
        }
        static void Main(string[] args)
        {
           inheri obj = new inheri();
            obj.mode();
            obj.feature();
            obj.Noise();
            Console.Read();
        }
    }
    class Mode
    {
        public void mode()
        {
            Console.WriteLine("There are Many Modes of Transport !!");
        }
    }
    class vehicle : Mode
    {
        public void feature()
        {
            Console.WriteLine("They Mainly Help in Travelling !!");
        }
    }
}
Program Explanation

This C# program is used to demonstrate multilevel inheritance. Here when a derived class is created from another derived class, then that inheritance is called as multi-level inheritance. We have created a inherit namespace.

 

Create a class inheri() procedure that inherit the vehicle class. Create the variable ‘obj’ as an object for inheri() procedure . Using the ‘obj’ object variable we are calling the mode(), feature(), Noise() function.

Runtime Test Cases
 
There are Many Modes of Transport !!
They Mainly Help in Travelling !!
All Vehicles Creates Noise !!