— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet215/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   211   212   213   214   215   216   217   218   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Tiger
Animal
Canine
Hippo
Dog
Wolf
Cat
Lion
Feline


222
 
chapter 8
So what we REALLY need is:
Æ
A way to have pet behavior in 
just 
the pet classes
Æ
A way to guarantee that all pet classes have all of the same 
methods defined (same name, same arguments, same return 
types, no missing methods, etc.), without having to cross your 
fingers and hope all the programmers get it right.
Æ
A way to take advantage of polymorphism so that all pets can have 
their pet methods called, without having to use arguments, return 
types, and arrays for each and every pet class.
Tiger
Animal
Canine
Hippo
Dog
Wolf
Cat
Lion
Feline
Pet
It looks like we need TWO 
superclasses at the top
We make a new abstract 
superclass called Pet, and 
give it all the pet methods.
Cat now extends 
from both Animal 
AND Pet, so it gets 
the methods of 
both.
Dog extends both 
Pet and Animal
The non-pet Animals 
don’t have any inherited 
Pet stuff.
multiple 
inheritance?


interfaces and 
polymorphism
you are here
4
223
It’s called “multiple inheritance”
and it can be a Really Bad Thing.
That is, if it were possible to do in Java. 
But it isn’t, because multiple inheritance has a problem 
known as The Deadly Diamond of Death.
There’s just one problem with the “two superclasses” approach...

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   211   212   213   214   215   216   217   218   ...   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