— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet181/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   177   178   179   180   181   182   183   184   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

exploiting the power of 
polymorphism
With polymorphism, you can write code that doesn’t 
have to change when you introduce new subclass 
types into the program.
Remember that Vet class? If you write that Vet class using 
arguments declared as type Animal, your code can handle any 
Animal subclass. That means if others want to take advantage of 
your Vet class, all they have to do is make sure their new Animal 
types extend class Animal. The Vet methods will still work, even 
though the Vet class was written without any knowledge of the 
new Animal subtypes the Vet will be working on. 
Why is polymorphism guaranteed to work this way? Why is 
it always safe to assume that any subclass type will have the 
methods you think you’re calling on the superclass type (the 
superclass reference type you’re using the dot operator on)?
brain
power
A


inheritance and 
polymorphism
you are here
4
189
Q: 
Are there any practical limits 
on the levels of subclassing? How 
deep can you go?
A: 
If you look in the Java API, 
you’ll see that most inheritance 
hierarchies are wide but not deep. 
Most are no more than one or two 
levels deep, although there are 
exceptions (especially in the GUI 
classes). You’ll come to realize that 
it usually makes more sense to keep 
your inheritance trees shallow, but 
there isn’t a hard limit (well, not one 
that you’d ever run into).
Q: 
Hey, I just thought of 
something... if you don’t have 
access to the source code for a class, 
but you want to change the way a 
method of that class works, could 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   177   178   179   180   181   182   183   184   ...   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