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 ....
Loading
Sunny SharmaPosted May 27, 2013, 12:07 PM
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
{
///
/// Properties of the car
///
private int _NoOfDoors { get; set; }
private int _NoOfWheels { get; set; }
///
/// Method to set the properties
///
///
///
public void UpdateDetails(int NoOfDoors, int NoOfWheels)
{
_NoOfDoors=NoOfDoors;
_NoOfWheels = NoOfWheels;
}
///
/// Method to get the properties
///
///
public string getDetails()
{
return string.Format("No. of Doors: {0}\n No. Wheels:{1}", _NoOfDoors, _NoOfWheels);
}
///
/// Other Properties (Optional)
///
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.
Sunny SharmaPosted May 27, 2013, 12:07 PM
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
{
///
/// Properties of the car
///
private int _NoOfDoors { get; set; }
private int _NoOfWheels { get; set; }
///
/// Method to set the properties
///
///
///
public void UpdateDetails(int NoOfDoors, int NoOfWheels)
{
_NoOfDoors=NoOfDoors;
_NoOfWheels = NoOfWheels;
}
///
/// Method to get the properties
///
///
public string getDetails()
{
return string.Format("No. of Doors: {0}\n No. Wheels:{1}", _NoOfDoors, _NoOfWheels);
}
///
/// Other Properties (Optional)
///
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.