— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet162/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   158   159   160   161   162   163   164   165   ...   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
How would you represent a house cat and a tiger, in an 
inheritance structure. Is a domestic cat a specialized 
version of a tiger? Which would be the subclass and 
which would be the superclass? Or are they both 
subclasses to some other class? 
How would you design an inheritance structure? What 
methods would be overridden? 
Think about it. Before you turn the page.
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.
brain
power
A


168
 
chapter 7
Understanding Inheritance
When you design with inheritance, you put common code in
a class and then tell other more specific classes that the
common (more abstract) class is their superclass. When one
class inherits from another,

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   158   159   160   161   162   163   164   165   ...   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