CS_0024_Creating Classes2



//  Program 24 : Creating Classes 2


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

namespace MOD17_inheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            Car myCar = new Car();
            Name myName = new Name ();


            myCar.Make = "TATA";
            myCar.Model = "INDICA";
            myCar.Year = 2005;
            myCar.Color = "GREY";

            myName.word1 = "I";
            myName.word2 = "AM";
            myName.word3 = "MATHI";
            myName.word4 ="KRISHNAN";

            carDetails (myCar);
            nameDetails (myName );

            Console.ReadLine ();

        }








        private static void carDetails(Car car)
       

    {
        Console.WriteLine(" My CAR Details:{0}", car.formatMe()  );
       
    }

       
        private static void nameDetails(Name name)

    {
       
        Console.WriteLine(" My Name Details:{0}", name.formatMeName()  );
    }

            }

   
  

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public string formatMe()
        {
            return string.Format("{0}-{1}-{2}-{3}",
                this.Make,
                this.Model,
                this.Year,
                this.Color);
        }
    }







    class Name
    {
        public string word1 { get; set; }
        public string word2 { get; set; }
        public string word3 { get; set; }
        public string word4 { get; set; }

        public string formatMeName()
        {
            return string.Format("{0}-{1}-{2}-{3}",
                this.word1,
                this.word2,
                this.word3,
                this.word4);
        }
    }

   
}


Results:

 My CAR Details:TATA-INDICA-2005-GREY
 My Name Details:I-AM-MATHI-KRISHNAN


Comments