— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

    Bu sahifa navigatsiya:
  • BRAD
BRAD: That’s the last step. The Amoeba class overrides the 
methods of the Shape class. Then at runtime, the JVM knows exactly 
which rotate() method to run when someone tells the Amoeba to rotate.
O
ve
rride Now
Ask Me H
o
w
I made the Amoeba class override
the rotate() method of the
superclass Shape.
Overriding just means that a
subclass redefines one of its
inherited methods when it needs
to change or extend the behavior
of that method.
4
Triangle
Square
Circle
Amoeba
rotate()
// amoeba-specific
// rotate code
playSound()
// amoeba-specific
// sound code
Shape
rotate()
playSound()
superclass
(more abstract)
subclasses
(more specific)
Overriding methods
LARRY: How do you “tell” an Amoeba to 
do something? Don’t you have to call the 
procedure, sorry—method, and then tell it 
which thing to rotate?
BRAD: That’s the really cool thing about OO. 
When it’s time for, say, the triangle to rotate, 
the program code invokes (calls) the rotate() 
method 
on the triangle object. The rest of the 
program really doesn’t know or care how the 
triangle does it. And when you need to add 
something new to the program, you just write 
a new class for the new object type, so the new 
objects will have their own behavior.
I can take 
care of myself. 
I know how an Amoeba 
is supposed to rotate 
and play a sound.
I know how a Shape is 
supposed to behave. Your 
job is to tell me 
what
 to 
do, and my job is to make it happen. 
Don’t you worry your little program-
mer head about 
how
I do it.
I made the Amoeba class override 
the rotate() and playSound() 
methods of the superclass Shape.
Overriding just means that a 
subclass redefines one of its 
inherited methods when it needs 
to change or extend the behavior 
of that method.
{
{
{
{



Download 40,57 Mb.

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