111,126
社区成员
发帖
与我相关
我的任务
分享
public class Car
{
public int Weight { get; set; }
public int Speed { get; set; }
public Car()
{
}
public Car(int weight,int speed)
{
this.Weight = weight;
this.Speed = speed;
}
public virtual void GetCarInfo()
{
Console.WriteLine("Car Weight:" + Weight.ToString() + ",Car Speed:" + Speed.ToString());
}
}
public class SportsCar:Car
{
public System.Drawing.Color CarColor
{
get;
set;
}
public SportsCar()
{ }
public SportsCar(int weight,int speed,System.Drawing.Color color):base(weight,speed)
{
this.CarColor = color;
}
public override void GetCarInfo()
{
base.GetCarInfo();
Console.WriteLine(this.CarColor.ToString());
}
}
static void Main(string[] args)
{
Car car = new Car { Weight = 100, Speed = 200 };
SportsCar sportCar = new SportsCar { Weight = 100, Speed = 200,CarColor=System.Drawing.Color.Red };
car.GetCarInfo();
sportCar.GetCarInfo();
Console.ReadLine();
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Car car = new Car(1000, 80);
Console.WriteLine("汽车的重量为:{0},速度为:{1}", car.Weight, car.Speed);
SportCar sportCar = new SportCar(2000, 120, Color.Red);
Console.WriteLine("跑车的重量为:{0},速度为:{1},颜色为:{2}", sportCar.Weight, sportCar.Speed, sportCar.Color.ToString());
Console.Read();
}
}
public class Car
{
public Car(double weight, double speed)
{
this.m_Weight = weight;
this.m_Speed = speed;
}
private double m_Weight;
/// <summary>
/// 重量
/// </summary>
public double Weight
{
get { return this.m_Weight; }
set { this.m_Weight = value; }
}
private double m_Speed;
/// <summary>
/// 速度
/// </summary>
public double Speed
{
get { return this.m_Speed; }
set { this.m_Speed = value; }
}
}
public class SportCar : Car
{
public SportCar(double weight, double speed, Color color)
: base(weight, speed)
{
this.m_Color = color;
}
private Color m_Color;
/// <summary>
/// 颜色
/// </summary>
public Color Color
{
get { return this.m_Color; }
set { this.m_Color = value; }
}
}
}
public class Car
{
public Car()
{
}
public Car(float weight,float speed)
{
this._weight = weight;
this._speed = speed;
}
private float _weight;
public float Weight
{
get;
set;
}
private float _speed;
public float Speed
{
get;
set;
}
public virtual void WriteInfo()
{
Console.WriteLine("重量:" + this._weight.ToString() + ",速度:" + this._speed.ToString());
}
}
public class RunCar : Car
{
public RunCar(float weight, float speed, ConsoleColor color):base(weight, speed)
{
this._color = color;
}
private ConsoleColor _color;
public ConsoleColor Color
{
get;
set;
}
public override void WriteInfo()
{
base.WriteInfo();
Console.WriteLine("颜色:" + this._color.ToString());
}
}
static void Main(string[] args)
{
Car car = new Car(12f, 34f);
Car runcar = new RunCar(23f, 55f, ConsoleColor.Red);
car.WriteInfo();
runcar.WriteInfo();
}