错误覆盖上一个bool抽象方法 [英] error on overriding a bool abstract method
本文介绍了错误覆盖上一个bool抽象方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不理解为什么会出现这个错误在我的派生类中一个将覆盖布尔方法
公共类的Hotrod:赛车
{
私人布尔风机=真||假;
公众的Hotrod();
公众的Hotrod(字符串racerName,诠释racerSpeed,发动机_engine);
{
racerName =名称;
racerSpeed =速度;
发动机=引擎;
}
公众覆盖布尔IsDead()
{
发动机发动机1 =新引擎();
发动机=发动机1;
随机RND =新的随机();
rnd.NextDouble();
布尔死= FALSE;
如果(racerSpeed大于50&放大器;&放大器; rnd.NextDouble()> 0.6)
如果(engine1.horsePower&所述; 300&放大器;&放大器;鼓风机==真)
死= FALSE;
,否则
死了= TRUE;
,否则如果(racerSpeed大于100&放大器;&放大器; rnd.NextDouble()> 0.4)
如果(engine1.horsePower> = 300&放大器;&放大器;送风机== true)而
死了= TRUE;
,否则
死= FALSE;
,否则
死= FALSE;
返回死了。
}
公共重写字符串的ToString()
{
字符串输出;
输出=\\\
============的Hotrod信息============
输出+ =\\\
\t赛车的名称:\t+ racerName;
输出+ =\\\
\t车速:\t+ carSpeed;
输出+ =\\\
\t Engine油缸:\t+ engineCylinders;
输出+ =\\\
\t发动机马力:\t+ engineHorsePower;
输出+ =n\t赛车的类型:\t+ racerType;
输出+ =n\t赛车用鼓风机:\t+ carBlower;
输出+ =n\t仍然工作:\t+ IsDead;
返回输出;
}
}
该错误是太布尔和预期类的说,委托,枚举,接口或结构
我能得到这个
解决方案任何帮助DIV>
是IsDead()在抽象类是虚方法?
覆盖必须是虚方法。
I'm not understanding why there is this error in my derived class to overide a method boolean
public class HotRod : Racer
{
private bool blower = true || false;
public HotRod();
public HotRod(string racerName, int racerSpeed, Engine _engine);
{
racerName = name;
racerSpeed = speed;
Engine = engine;
}
public override bool IsDead()
{
Engine engine1 = new Engine();
Engine = engine1;
Random rnd = new Random();
rnd.NextDouble();
bool dead = false;
if (racerSpeed > 50 && rnd.NextDouble() > 0.6)
if (engine1.horsePower < 300 && blower == true)
dead = false;
else
dead = true;
else if (racerSpeed > 100 && rnd.NextDouble() > 0.4)
if (engine1.horsePower >= 300 && blower == true)
dead = true;
else
dead = false;
else
dead = false;
return dead;
}
public override string ToString()
{
string output;
output = "\n============ HotRod Information ============";
output += "\n\t Racer's Name:\t" + racerName;
output += "\n\t Car's Speed:\t" + carSpeed;
output += "\n\t Engine Cylinders:\t" + engineCylinders;
output += "\n\t Engine Horsepower:\t" + engineHorsePower;
output += "n\t Racer's Type:\t" + racerType;
output += "n\t Racer with Blower:\t" + carBlower;
output += "n\t Still Working?:\t" + IsDead;
return output;
}
}
The error is too the bool and says Expected class, delegate, enum, interface, or struct
can I get any help with this
解决方案
Is IsDead() in the abstract class is virtual method?
Override must be virtual method.
这篇关于错误覆盖上一个bool抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文