public class Car{
//Car的字段(状态)
private int _speed;
private string _name; //Car操作字段的属性
public int Speed
{
set {this._speed=value;}
get{return this._speed;}
}
public string Name
{
set { this._name=value;}
get{return this._name;}
}
//显式定义默认构造函数
public Car(){} //自定义构造函数
public Car(string name,int speed)
{
this._name=name;
this._speed=speed;
}
//Car的功能(方法)
public void ShowState()
{Console.WriteLine("Car {0} is going {1} MPH", this._name,this. _speed);}}
class Car{
public int Speed{get;set;}
public string Name{get;set;}
public Car(){}
public Car(int speed){if(speed>150){speed=150;}this.Speed=speed;}
public Car(string name){this.Name=name;}
public Car(int speed,string name){if(speed>150){speed=150;}this.Speed=speed;this.Name=name;}}
class Car{
public int Speed{get;set;}
public string Name{get;set;}
public Car(){}
public Car(int speed):this(speed,""){}
public Car(string name):this(0,name){} // 主构造函数 public Car(int speed,string name)
{
if(speed>150) {speed=150;} this.Speed=speed;
this.Name=name;
}}