主要原因是大小些的问题,C#是区分的。还有重复定义了一个变量。由于错误太多,我只好把改好的东西贴上来。using System;
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 Train    //定義火車類
{
public int num;//公有成員:車廂數目
private int passengers; //私有成員:乘客數
private  float weight;//私有成員:重量
public Train(){;}
public Train(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 train car is:{0}",passengers);
     }
} class Car:Vehicle  
{
int passengers;     //私有成員:乘客數
//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 is:{0}", wheels);
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 Train();
Train t2=new Train(10,100,100);
Car c1=new Car(4,2,4);
v1.Show();
t1.Show();
t2.Show();
c1.Show();
Console.Read();
}
}----------------------
下面是我计算机上的结果,不知道是不是你要的。
the wheel of vehicle is:4
the weight of Vehicle is:5
the num of train is:0
the weight of train is:0
the Passengers train car is:0
the num of train is:10
the weight of train is:100
the Passengers train car is:100
the wheel of car is:4
the weight of car is:2
the Passengers of car is:4

解决方案 »

  1.   

    仁兄,你的问题就是一些大小写的问题,我也改了一遍,把代码贴出来供你参考了:)
    using System;
    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 train    //定義火車類
    {
    public int num;//公有成員:車廂數目
    private int passengers; //私有成員:乘客數
    private  float weight;//私有成員:重量
    public train(){;}
    public train(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 train car is:{0}",passengers);
         }
    } class Car:Vehicle  
    {
    int passengers;     //私有成員:乘客數
    //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 is:{0}", wheels);
    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 train();
    train t2=new train(10,100,100);
    Car c1=new Car(4,2,4);
    v1.Show();
    t1.Show();
    t2.Show();
    c1.Show();
    }
    }