<< Chapter < Page Chapter >> Page >

The interface named IVolume declares one method named volume . Likewise, the interface named ICircumference declares one method named circumference .

The rules of the road

Any number of classes can implement the same interface. This makes it possible to treat objects instantiated from different classes as the commoninterface type.

A class can implement any number of interfaces. In this program, however, the classes named MyRectangle and MyCircle each implement only one interface named IArea .

Can extend any number of interfaces

An interface can extend any number of other interfaces. In this program, the IArea interface extends both the IVolume interface and the ICircumference interface.

The bottom line

Implementing the IArea interface causes both the MyRectangle class and the MyCircle class to inherit the following abstract methods:

  • area
  • id
  • circumference
  • volume

The first two methods are inherited directly from the interface named IArea . The last two are inherited from the interfaces named ICircumference and IVolume by way of IArea .

Each of the two classes must provide concrete definitions for all four of the inherited abstract methods.

Program output at startup

Figure 2 shows the program output at startup.

Program output at startup.

Missing image
Program output at startup.

The program GUI

The program GUI consists of one label , three buttons and a text area . When a button is clicked, a random process is used to instantiate an object ofeither the MyCircle class or the MyRectangle class. The new object's reference is saved in a variable of the interface type IArea . This is possible because both classes implement the common IArea interface.

Call methods using the reference of type IArea

Then, as a result of a click on a button, the program calls the id method on the object whose reference is stored in the variable of type IArea . Depending on which button is clicked, the program then calls either the area method, the circumference method, or the volume method on the object.

Output after clicking the Area Button for circle

Clicking the button labeled Area, for example causes the output to change to something similar to either Figure 3 or Figure 4. An output similar toFigure 3 is produced if the random process instantiates an object of the MyCircle class.

Output after clicking the area button for circle.

Missing image
Output after clicking the Area Button for circle.

Output after clicking the Area Button for rectangle

An output similar to Figure 4 is produced if the random process instantiates an object of the MyRectangle class.

Output after clicking the area button for rectangle.

Missing image
Output after clicking the Area Button for rectangle.

Random radius, width, and height

I use the word similar because a random process is also used to establish the radius for the circle and to establish the width and height for the rectangle.

Both the MYCircle object and the MyRectangle object contain concrete versions of the four methods listed above . However, the behavior of those four methods in one object is different from the behavior of the four methods havingthe same names in the other object.

Questions & Answers

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 environments
AI-Robot
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
cell is the building block of life.
Condoleezza Reply
what is cell divisoin?
Aron Reply
Diversity of living thing
ISCONT
what is cell division
Aron Reply
Cell division is the process by which a single cell divides into two or more daughter cells. It is a fundamental process in all living organisms and is essential for growth, development, and reproduction. Cell division can occur through either mitosis or meiosis.
AI-Robot
What is life?
Allison Reply
life is defined as any system capable of performing functions such as eating, metabolizing,excreting,breathing,moving,Growing,reproducing,and responding to external stimuli.
Mohamed
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, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask