— Scott McNealy, Sun Microsystems Chairman, President and ceo


the subclass inherits from the



Download 40,57 Mb.
Pdf ko'rish
bet163/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   159   160   161   162   163   164   165   166   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

the subclass inherits from the
superclass.
In Java, we say that the subclass extends the superclass.
An inheritance relationship means that the subclass inherits
the
members
of the superclass. When we say “members of
a class” we mean the instance variables and methods.
For example, if PantherMan is a subclass of SuperHero, the
PantherMan class automatically inherits the instance variables
and methods common to all superheroes including
suit
,
tights
,
specialPower
,
useSpecialPowers()
, and
so on. But the PantherMan
subclass can add new
methods and instance variables
of its own, and it
can
override the methods it inherits from the superclass
SuperHero.
SuperHero
suit
tights
specialPower
useSpecialPower()
putOnSuit()
superclass
(more abstract)
subclasses
(more specific)
Overriding
methods
PantherMan
useSpecialPower()
putOnSuit()
instance variables
(state, attributes)
methods
(behavior)
FriedEggMan doesn’t need any behavior that’s unique,
so he doesn’t override any methods. The methods and
instance variables in SuperHero are sufficient.
PantherMan, though, has specific requirements for his suit
and special powers, so
useSpecialPower()
and
putOnSuit()
are both overridden in the PantherMan
class.
Instance variables are not overridden
because they
don’t need to be. They don’t define any special behavior, so a
subclass can give an inherited instance variable any value it
chooses. PantherMan can set his inherited
tights
to
purple, while FriedEggMan sets his to white.
FriedEggMan
the way 
inheritance 

Download 40,57 Mb.

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