using System;
calss 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 train //定义火车类
{
public int num;//公有成员:车厢数目
private int passengers;//私有成员:乘客数
private float weight;//私有成员:重量
public Train(){;}
public Trian(int n,int p,float w)
{
num = n;
passengers = p;
weight = w;
}
public void Show()
{
Console.WriteLine("the num of train is :{0}",num );
Console.WriteLine("the weight of train is :{0}",weight);
Console.WriteLine("the Passengers of train is :{0}",Passengers );
}
}
class Car:Vehicle//定义轿车类
{
int passengers;//私有成员:乘客数
public Car(int w,float g,int p):base(w,g)
{
wheels = w;
weight = g;
passengers = p;
}
new public void Show()
{
Console.WriteLine("the wheel of car :{0}",num );
Console.WriteLine("the weight of car is :{0}",weight);
Console.WriteLine("the Passengers of car is :{0}",Passengers );
}
}
class Test
{
public static void Main(){
Vehicle v1 = new Vehicle(4,5);
Train t1 = new Trian();
Trian t2 = new Trian(10,100,100);
Car c1 = new Car(4,2,4);
v1.show();
t1.show();
t2.show();
c1.show();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
程序的运行结果为:
the wheel of vehicle is:0
the weight of vehicle is 0
the num of train is:0
the weight of train is:0
the Passengers of train is:0
the num of trian is:10
the weight of train is:100
the Passengers of trin is:100
the wheel of car is:4
the weight of car is:2
the Passebger of car is:4
|