主要是大小写的问题,注意C#中区分大小写。这是我改正的代码:using System;namespace TestCon
{
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();
}
}
}
___________________________________
too simple,sometimes naive :()
___________________________________
{
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();
}
}
}
___________________________________
too simple,sometimes naive :()
___________________________________
解决方案 »
- 求多页面打印问题
- C#的大工程,打算从.net2.0升级到3.5版本,有什么地方需要注意/修改的?
- 判断是否安装了软件
- C#调用dll出现异常
- C#中利用dataGrid控件进行数据库邦定时,利用SQL语句怎么接受新输入的变量啊?
- 如何自己实现最小化?
- 未将对象引用设置到对象的实例
- 急,使用npoi导出grid中的数据到excel中时,保存的路径是通过弹窗自己选择的,目前的路径是写死的。
- DevExpress建立的窗体中,有一个查询功能,当查询结果为空时,弹出提示框怎么实现
- 关于datagid的分页问题——求助,急。。。。在线等待
- 我写了个控件拖放,象数扫描,打印。。。。。的C#程序,有人要代码吗?顺便帮我看看问题。
- 有关C#和asp.net!!
我的缩进没有了:)___________________________________
too simple,sometimes naive :()
___________________________________