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

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?