class Vehicle
{
public int wheels;//公共成员,轮子数
protected float weight;//保护成员,重量
public void F()
{
wheels = 4;
weight = 10;
}
}
class Car : Vehicle
{
int passenages;
public void F()//有意隐藏,要用什么new
{
Vehicle v2 = new Vehicle();
v2.wheels = 6;
v2.weight = 6;//出错,无法访问
}
}Car类从Vehicle继承,//为出错位置,按道理,派生类应该可以从基类里面继承到protected变量啊
还有就是方法F()问题,有意隐藏,要用什么new这样的警告
{
public int wheels;//公共成员,轮子数
protected float weight;//保护成员,重量
public void F()
{
wheels = 4;
weight = 10;
}
}
class Car : Vehicle
{
int passenages;
public void F()//有意隐藏,要用什么new
{
Vehicle v2 = new Vehicle();
v2.wheels = 6;
v2.weight = 6;//出错,无法访问
}
}Car类从Vehicle继承,//为出错位置,按道理,派生类应该可以从基类里面继承到protected变量啊
还有就是方法F()问题,有意隐藏,要用什么new这样的警告
解决方案 »
- 求助 C#拦截本地所有HTTP请求
- C#中XML问题
- C#扫雷,将游戏用时最短者的姓名和时间,保存到排行榜,这个功能怎么做呢?
- C# 给webbrowser中的控件自动填写值
- c#数据与图开联动
- 请高手讲解一下C#开发 com的过程!
- ##########大家有谁做过或知道哪有用.net做的闹钟的程序?##############
- 关于打印的一点问题
- 如何在server端产生访问<input type="image">的事件
- 部署问题,制作安装程序时如何得到用户选择的路径和在开始菜单中添加卸载选项?
- 菜鸟求问COMBOX的问题,为什么两个COMBOX会有数据干扰?
- 正则表达式“<(p|br)[^<]*>”分析
你把这个换成Car V2=new Car()就不会错了,想想原因吧。
new public void F()//有意隐藏,要用什么new
{
Vehicle v2 = new Vehicle();
v2.wheels = 6;
v2.weight = 6;//出错,无法访问
}
这是强制重写基类方法的意思
class Vehicle
{
public int wheels;//公共成员,轮子数
protected float weight;//保护成员,重量
protected visual void F()
{
wheels = 4;
weight = 10;
}
}
class Car : Vehicle
{
int passenages;
protected override void F()//有意隐藏,要用什么new
{
Vehicle v2 = new Vehicle();
v2.wheels = 6;
v2.weight = 6;//出错,无法访问
}
}把基类方法F做成虚函数