SEARCH C# PROGRAMMING CODES HERE

Single-level Inheritance

Single-level Inheritance in C#
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
Brand -BMW
Max_Speed -200-MPH