SEARCH C# PROGRAMMING CODES HERE

Inheritance

Inheritance in C#
In C# Inheritance is a significant thought where you describe parent classes and child classes. inheritance enables us to characterize a class regarding another class, which makes it simpler to make and keep. This likewise gives a chance to reuse the code usefulness and accelerates execution time. The child classes acquire strategies and properties of the parent class, but, they can in like manner modify the lead of the strategies at whatever point required. The child class can in like manner describe systems for its very own at whatever point required. A class can be handled from more than one class or interface, which implies that it can acquire information and capacities from numerous base classes or interfaces.
so let's see the methods we implement in the programming using Inheritance.

Syntax

<Acess-Specifier> Class <Base_Class> 
{
   
}

Class <Derived_Class> : <Base_Class>

 {

 }

Methods

1-Single-level Inheritance
When one class acquires another class, it is called single-level Inheritance. The child classes inherit functions and properties of the parent class so let's see the program to figure out how single level inheritance work. Simply copy the yellow highlighted code as follows.
Program

using System;


namespace program
{
    public class Car   /*Base Class*/
    {
        public string brand = "BMW";
    }
    public class Feature : Car /*Derived Class*/
    {
        public int speed = 200;
    }
    class Inheritance
   {
        class Program
        {
            static void Main(string[] args)
            {
        /*Calling base class member using Derived Class*/
                Feature car = new Feature();
                Console.WriteLine("Brand - " + car.brand);
                Console.WriteLine("Max_Speed - " + car.speed + "-Mph");
                Console.ReadKey();
            }

        }

    }
}

As you can see In the above program, Car is the base class and Feature is the Derived class which acquires all the members of the base class.

  Output




















2-Multi-level Inheritance 
When one class acquires another class which is additionally acquired by another class, in this case, we will call it Multi-level Inheritance. Inheritance is transitive so the last decided class secures all of the information from all its base classes.so let's clear out through the program and simply copy the yellow highlighted code as follows.

Program

using System;
namespace program
{
    public class Car  /*Base class */
    {
        public void BMW()
        {
            Console.WriteLine("Manufracturer- BMW_Ltd_Corporation");
            Console.WriteLine("Car_Brand - BMW");
        }
    }
    public class BMW_Feature : Car
    {
        public void feature()
        {
            Console.WriteLine("Avalble_Color- Black,Blue,Red,White ");
            Console.WriteLine("Max_Speed - 200 MPH ");
            Console.WriteLine("Price=23,00000");
        }
    }
    public class Detail: BMW_Feature /*Derived class */
    {
        public void Bmw_Detail()
        {
            BMW();
            feature();
        }
    }
   
    class Inheritance
    {
        class Program
        {
            static void Main(string[] args)
            {
 /*Calling all the base classes members using Derived Class*/
             Detail Car = new Detail();
             Car.Bmw_Detail();
             Console.ReadKey();
            }

        }

    }
}

Now you can see in the above program last Derived class is Detail which acquires all the members of all its base classes.
   Output