很简单的类继承问题,在线等!

flcandclf 2004-12-01 09:34:15
using System;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
///


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 passenger;
private float weight;
public Train(){;}
public Train(int n,int p,float w)
{
num =n;
passenger=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 passenger train car is:{0}",passenger);
}
}

class Car:Vehicle
{
int passenger;
public Car(int w,float g,int p):base(w,g)
{
wheels = w;
weight = g;
passenger = p;
}

//为什么不执行这段代码?
public void Show()
{
Console.WriteLine("the wheel of car is:{0}",wheels);
Console.WriteLine("the weight of car is:{0}",weight);
Console.WriteLine("the passenger of car is:{0}",passenger);
}
}
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//


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.ReadLine();
}
}
}
为什么调用c1.show()的时候不执行类car里的show()?
...全文
109 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
BitNomad 2004-12-01
  • 打赏
  • 举报
回复
一个是大写一个是小写 呵呵
stonegoldaustin 2004-12-01
  • 打赏
  • 举报
回复
show()的第一个字母要大写
yani_33 2004-12-01
  • 打赏
  • 举报
回复
up

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧