<< Chapter < Page Chapter >> Page >

The effect of extending a class

The effect of having the Balloon class extend the Airship class is different from anything that you have seen in previous modules. When one class extends another class, the new class inherits all ofthe properties, events, and methods of the superclass and all of its superclasses.

Airship extends Object

In this case, the Airship class extends the Object class by default. Therefore, an object instantiated from the Balloon class contains:

  • The two properties defined in the Balloon class in Listing 2 .
  • The two properties defined in the Airship class in Listing 1 .
  • The eight methods defined in the Object class discussed earlier .

The beginning of the Driver class

At this point, I am going to show and explain the first half of the Driver class (see Listing 3 ) and relate it to the program output shown in Figure 1 .

Listing 3 . The beginning of the Driver class.

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

For convenience and because of their small sizes, I elected to define all four classes in the same file as the file that contains the Driver class with the Main method. That is not a requirement, however, and on large projects you may want to put each class definition inits own file.

Code common to all four classes

The single line of code at the very beginning of Listing 3 applies to all four classes. You have seen this before so it should not be new to you.

Instantiate a new Balloon object

The Main method begins by instantiating a new object of the Balloon class and saving its reference in a reference variable of type Balloon named balloon . This reference will be used later to access the new object.

Set properties in the Balloon object

Then the Main method calls the four set methods belonging to the new Balloon object, using them to set values into the four properties belonging to the Balloon object.

Remember that the set methods that hide two of the properties are defined in the Airship class and are inherited into the Balloon class. The other two set methods are defined in the Balloon class.

Get and display property values

After that, the Main method calls the four get methods belonging to the new Balloon object, using them to get and display values from the four properties belonging to the new Balloon object.

The get methods that hide two of the properties are defined in the Airship class and are inherited into the Balloon class. The other two get methods are defined in the Balloon class.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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