— Scott McNealy, Sun Microsystems Chairman, President and ceo


tree relationships (step 4-5)



Download 40,57 Mb.
Pdf ko'rish
bet165/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   161   162   163   164   165   166   167   168   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

tree relationships (step 4-5)
Let’s design the inheritance tree for 
an Animal simulation program
Imagine you’re asked to design a simulation program that 
lets the user throw a bunch of different animals into an 
environment to see what happens. We don’t have to code the 
thing now, we’re mostly interested in the design.
We’ve been given a list of some of the animals that will be 
in the program, but not all. We know that each animal will 
be represented by an object, and that the objects will move 
around in the environment, doing whatever it is that each 
particular type is programmed to do.
And we want other programmers to be able to add new 
kinds of animals to the program at any time.
First we have to figure out the common, abstract 
characteristics that all animals have, and build those 
characteristics into a class that all animal classes can extend.
1
Look for objects that have common 
attributes and behaviors.
designing for 
inheritance


inheritance and 
polymorphism
you are here
4
171
These objects are all animals, so 
we’ll make a common superclass 
called Animal.
We’ll put in methods and instance 
variables that all animals might 
need.
2
Design a class that represents 
the common state and behavior.
Animal
picture
food
hunger
boundaries
location
makeNoise()
eat()
sleep()
roam()
We have fi ve 
instance variables
:
picture
– the fi le name representing the JPEG of this animal
food 
– the type of food this animal eats. Right now, there 
can be only two values: meat or grass.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   161   162   163   164   165   166   167   168   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish