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

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.41.229