program for inheritance in c#.net use class and subclass

program for inheritance in c#.net using class :


In this assignment you will make a console application with a simple Car class. The Car class holds two pieces of information: the speed of the car and the model of the car. In your program you will make one object of the Car class, set his model (e.g., Audi) and starting speed (e.g., 25 km/h) and then change the value of the speed several times. 


program for inheritance in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace qus1
{

    class car
    {
        string model="Audi";
        int speed=25;

        
        public void print()
        {

            Console.WriteLine("Starting Speed of: " + model + " is " + speed);

            for (int i = 0; i < 1000; i++)
            {
                if (i == 50)
                {
                    Console.WriteLine("Starting Speed of: " + model + " is " + i + "/km");
                }
                if (i == 51)
                {
                    Console.WriteLine("Starting Speed of: " + model + " is " + i + "/km");
                }
                if (i == 98)
                {
                    Console.WriteLine("Starting Speed of: " + model + " is " + i + "/km");
                }
                if (i == 968)
                {
                    Console.WriteLine("Starting Speed of: " + model + " is " + i + "/km");
                }
            }

            Console.Out.WriteLine("For exite press enter ");
            Console.Read();

        }
    }



    class Program : car
    {


        static void Main(string[] args)
        {
            car mycar = new car();

            mycar.print();

            



        }

    }

}


Result of Program for inheritance in c#




Comments

Popular posts from this blog