官术网_书友最值得收藏!

How to do it...

  1. Create an abstract class called Shuttle and give it a member called TWR, which is the calculation of the TWR of the shuttle:
        public abstract class Shuttle 
{
public abstract double TWR();
}
  1. Next, create a class called NasaShuttle and have it inherit from the abstract class Shuttle by putting the abstract class name after a colon at the end of the NasaShuttle class declaration:
        public class NasaShuttle : Shuttle 
{

}
  1. Visual Studio will underline the NasaShuttle class because you have told the compiler that the class inherits from an abstract class, but you have not yet implemented the members of that abstract class:
  1. To fix the issues identified, type Ctrl . (control key and period) and let Visual Studio show you some potential fixes (in this case, only one fix) for the issues identified:
  1. Visual Studio then adds the missing implementation to your NasaShuttle class. By default, it will add it as not implemented, because you are required to provide implementation for the abstract member you overrode in the abstract class:
        public class NasaShuttle : Shuttle 
{
public override double TWR()
{
throw new NotImplementedException();
}
}
  1. Create another class called RoscosmosShuttle and inherit from the same Shuttle abstract class:
        public class RoscosmosShuttle : Shuttle 
{

}
  1. As before, Visual Studio will underline the RoscosmosShuttle class because you have told the compiler that the class inherits from an abstract class, but you have not yet implemented the members of that abstract class.
  1. To fix the issues identified, type Ctrl . (control key and period) and let Visual Studio show you some potential fixes (in this case, only one fix) for the issues identified.
  1. The overridden method is then added to the RoscosmosShuttle class as not implemented. You have just seen an example of dynamic polymorphism in action:
        public class RoscosmosShuttle : Shuttle 
{
public override double TWR()
{
throw new NotImplementedException();
}
}
  1. To see an example of static polymorphism, create the following overloaded constructor for NasaShuttle. The constructor name stays the same, but the signature of the constructor changes, which makes it overloaded:
        public NasaShuttle(double engineThrust, 
double totalShuttleMass, double gravitationalAcceleration)
{

}

public NasaShuttle(double engineThrust,
double totalShuttleMass, double planetMass,
double planetRadius)
{

}
主站蜘蛛池模板: 桑植县| 灌阳县| 新巴尔虎右旗| 永仁县| 遂宁市| 隆昌县| 当涂县| 灵石县| 吴忠市| 天水市| 丹寨县| 分宜县| 舟曲县| 濉溪县| 策勒县| 麟游县| 长葛市| 竹山县| 迁西县| 潼南县| 米易县| 桐城市| 固始县| 双流县| 南部县| 合作市| 班玛县| 扎鲁特旗| 阳西县| 青河县| 三门峡市| 沐川县| 广东省| 府谷县| 罗甸县| 烟台市| 嘉定区| 霍林郭勒市| 邵东县| 泗洪县| 河北省|