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

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)
{

}
主站蜘蛛池模板: 丽江市| 新化县| 高陵县| 英德市| 定南县| 镇原县| 英山县| 梅河口市| 阜康市| 宝丰县| 塘沽区| 中山市| 青河县| 随州市| 武穴市| 申扎县| 平陆县| 拉萨市| 石渠县| 武宣县| 云龙县| 乌海市| 苍南县| 弥勒县| 灵山县| 潮安县| 星子县| 奉化市| 策勒县| 五华县| 丽水市| 拉萨市| 澜沧| 白朗县| 徐州市| 西吉县| 梓潼县| 石狮市| 永济市| 无棣县| 沛县|