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.

advertisement
advertisement

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 !!

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.