Skip to content

OOPS OBJECT

Sinu  Joseph

Sinu Joseph

Asked May 27, 2013, 6:58 AM EDT2 answers
Share
LinkedInX
craete a class called "car" with 2 data members namely :"No Of doors" and "no of wheels" create 2 methods to accept the values of the said data members and to display the values on the screen. create an object to test the above class;

can u plz help me with explanation ....

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi sinu joseph,

    Below is the implementation of Car class having No. of wheels and Doors and properties and two methods to get and set those properties. They're quite self-explanatory.
    --------------------------------------------------------------------------------


    class Program
    {
    class Car
    {
    /// <summary>
    /// Properties of the car
    /// </summary>
    private int _NoOfDoors { get; set; }
    private int _NoOfWheels { get; set; }

    /// <summary>
    /// Method to set the properties
    /// </summary>
    /// <param name="NoOfDoors"></param>
    /// <param name="NoOfWheels"></param>
    public void UpdateDetails(int NoOfDoors, int NoOfWheels)
    {
    _NoOfDoors=NoOfDoors;
    _NoOfWheels = NoOfWheels;
    }

    /// <summary>
    /// Method to get the properties
    /// </summary>
    /// <returns></returns>
    public string getDetails()
    {
    return string.Format("No. of Doors: {0}\n No. Wheels:{1}", _NoOfDoors, _NoOfWheels);
    }


    /// <summary>
    /// Other Properties (Optional)
    /// </summary>
    public string Name { get; set; }
    public Car(string name)
    {
    this.Name = name;
    }

    }

    static void Main(string[] args)
    {
    Car car = new Car("Honda");
    car.UpdateDetails(2, 4); // Set the No. Of Doors & No. Of Wheels here.

    Console.WriteLine("Name of Car: " + car.Name);
    Console.WriteLine(car.getDetails()); // Get the Details of Car here
    Console.ReadLine();

    }
    }


    Happy Coding :)

    Please don't forget to accept this as answer if it helps you achieve your purpose as you increase the chances of help giving appropriate credit to author.
    Thanks.
    0
  • Sunny  Sharma
    0
    Hi sinu joseph,

    Below is the implementation of Car class having No. of wheels and Doors and properties and two methods to get and set those properties. They're quite self-explanatory.
    --------------------------------------------------------------------------------


    class Program
    {
    class Car
    {
    /// <summary>
    /// Properties of the car
    /// </summary>
    private int _NoOfDoors { get; set; }
    private int _NoOfWheels { get; set; }

    /// <summary>
    /// Method to set the properties
    /// </summary>
    /// <param name="NoOfDoors"></param>
    /// <param name="NoOfWheels"></param>
    public void UpdateDetails(int NoOfDoors, int NoOfWheels)
    {
    _NoOfDoors=NoOfDoors;
    _NoOfWheels = NoOfWheels;
    }

    /// <summary>
    /// Method to get the properties
    /// </summary>
    /// <returns></returns>
    public string getDetails()
    {
    return string.Format("No. of Doors: {0}\n No. Wheels:{1}", _NoOfDoors, _NoOfWheels);
    }


    /// <summary>
    /// Other Properties (Optional)
    /// </summary>
    public string Name { get; set; }
    public Car(string name)
    {
    this.Name = name;
    }

    }

    static void Main(string[] args)
    {
    Car car = new Car("Honda");
    car.UpdateDetails(2, 4); // Set the No. Of Doors & No. Of Wheels here.

    Console.WriteLine("Name of Car: " + car.Name);
    Console.WriteLine(car.getDetails()); // Get the Details of Car here
    Console.ReadLine();

    }
    }


    Happy Coding :)

    Please don't forget to accept this as answer if it helps you achieve your purpose as you increase the chances of help giving appropriate credit to author.
    Thanks.
    0