主题:c#构造函数?
class Vehicle //定义汽车类
{
public int wheels;//公有成员:轮子个数
protected float weight; //保护成员:重量
public Vehicle(){;}
public Vehicle(int w,float g)
{
wheels=w;weight=g;
}
public void Show()
{
Console.WriteLine("the wheel of vehicle is :{0}",wheels);
Console.WriteLine("the weight of vehicle is:{0}",weight);
}
};
class Car:Vehicle //定义轿车类
在这段代码中public Vehicle(){;}表示什么啊,它下面那个是构造函数啊,那它起什么作用啊?最后一行的定义轿车类是继承汽车类Vehicle吗?为什么是那个形式啊?
{
public int wheels;//公有成员:轮子个数
protected float weight; //保护成员:重量
public Vehicle(){;}
public Vehicle(int w,float g)
{
wheels=w;weight=g;
}
public void Show()
{
Console.WriteLine("the wheel of vehicle is :{0}",wheels);
Console.WriteLine("the weight of vehicle is:{0}",weight);
}
};
class Car:Vehicle //定义轿车类
在这段代码中public Vehicle(){;}表示什么啊,它下面那个是构造函数啊,那它起什么作用啊?最后一行的定义轿车类是继承汽车类Vehicle吗?为什么是那个形式啊?