<< Chapter < Page Chapter >> Page >

Complete program listing

A complete listing of the C# program discussed in this module is provided in Listing 4 .

Listing 4 . The program named Airship01.

/*Project Airship01 * Illustrates inheritance* ******************************************************/ using System;namespace Airship01 { //Define a class to exercise the Balloon class and the// Airplane class. class Driver {static void Main(string[] args) {Balloon balloon = new Balloon(); balloon.range = 5;balloon.altitude = 500; balloon.passengerCapacity = 5;balloon.liftMedia = "Hot Air"; Console.WriteLine("Balloon");Console.WriteLine( "range = " + balloon.range + " miles");Console.WriteLine( "altitude = " + balloon.altitude + " feet");Console.WriteLine("passenger capacity = " + balloon.passengerCapacity);Console.WriteLine("lift media = " + balloon.liftMedia);Airplane airplane = new Airplane(); airplane.range = 5000;airplane.altitude = 35000; airplane.cargoCapacity = 20000;airplane.engineType = "jet"; Console.WriteLine("");//blank lineConsole.WriteLine("Airplane"); Console.WriteLine("range = " + airplane.range + " miles"); Console.WriteLine("altitude = " + airplane.altitude + " feet"); Console.WriteLine("cargo capacity = "+ airplane.cargoCapacity + " pounds"); Console.WriteLine("engine type = "+ airplane.engineType); //Pause and wait for the user to press any key.Console.ReadKey(); }//end Main}//end class Driver //====================================================////Define common properties in the base class. class Airship {private int rangeData = 0; private int altitudeData = 0;public int range { get {return rangeData; }//end getset { rangeData = value;}//end set }//end range propertypublic int altitude { get {return altitudeData; }//end getset { altitudeData = value;}//end set }//end altitude property}//end class Airship //====================================================////Define unique properties in the subclass. class Balloon : Airship {private int passengerCapacityData; private String liftMediaData;public int passengerCapacity { get {return passengerCapacityData; }//end getset { passengerCapacityData = value;}//end set }//end passengerCapacity propertypublic String liftMedia { get {return liftMediaData; }//end getset { liftMediaData = value;}//end set }//end liftMedia property}//end Balloon class //====================================================////Define unique properties in the subclass. class Airplane : Airship {private int cargoCapacityData; private String engineTypeData;public int cargoCapacity { get {return cargoCapacityData; }//end getset { cargoCapacityData = value;}//end set }//end cargoCapacity propertypublic String engineType { get {return engineTypeData; }//end getset { engineTypeData = value;}//end set }//end engineType property}//end Airplane class //====================================================//}//end namespace Airship01

-end-

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Xna game studio. OpenStax CNX. Feb 28, 2014 Download for free at https://legacy.cnx.org/content/col11634/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Xna game studio' conversation and receive update notifications?

Ask
Hope Percle
Start Quiz
Yasser Ibrahim
Start Quiz
Edgar Delgado
Start Test