— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet51/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   47   48   49   50   51   52   53   54   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

BRAD: Oh, I guess you didn’t see the final design. Let me 
show you how OO 
inheritance
works, Larry. 
What Larry wanted
(figured the chair would impress her)
They’re Shapes, and they all rotate and
playSound. So I abstracted out the
common features and put them into a
new class called Shape.
Shape
rotate()
playSound()
Triangle
Square
Circle
Amoeba
Shape
rotate()
playSound()
superclass
subclasses
Then I linked the other 
four shape classes to 
the new Shape class, 
in a relationship called 
inheritance. 
Triangle
rotate()
playSound()
Square
rotate()
playSound()
Circle
rotate()
playSound()
I looked at what all four
classes have in common.
Amoeba
rotate()
playSound()
1
2
3
You can read this as, “Square inherits from Shape”
“Circle inherits from Shape”, and so on. I removed 
rotate() and playSound() from the other shapes, so now 
there’s only one copy to maintain.
The Shape class is called the superclass of the other four 
classes. The other four are the subclasses of Shape. The 
subclasses inherit the methods of the superclass. In other 
words, if the Shape class has the functionality, then the 
subclasses automatically get that same functionality.


once upon a time in 
Objectville
32
 
chapter 2
What about the Amoeba rotate()?
LARRY: Wasn’t that the whole problem here — that the amoeba shape 
had a completely different rotate and playSound procedure?
BRAD: Method.
LARRY: Whatever. How can amoeba do something different if 
it “inherits” its functionality from the Shape class?

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   47   48   49   50   51   52   53   54   ...   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