— Scott McNealy, Sun Microsystems Chairman, President and ceo


Tub int size; Bubbles b; Bubbles



Download 40,57 Mb.
Pdf ko'rish
bet171/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   167   168   169   170   171   172   173   174   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Tub
int size;
Bubbles b;
Bubbles
int radius;
int colorAmt;
Bathroom HAS-A Tub and Tub HAS-A Bubbles. 
But nobody inherits from (extends) anybody else.


exploiting the power of 
objects 
178
 
chapter 7
But wait! There’s more!
The IS-A test works anywhere in the inheritance tree. If your 
inheritance tree is well-designed, the IS-A test should make 
sense when you ask any subclass if it IS-A any of its supertypes.
If class B extends class A, class B IS-A class A.
This is true anywhere in the inheritance tree. If 
class C extends class B, class C passes the IS-A 
test for both B 
and A.
size
picture
food
prey
Wolf
Canine
roam()
makeNoise()
eat()
Animal
makeNoise()
eat()
sleep()
roam()
Canine extends Animal
Wolf extends Canine
Wolf extends Animal
Canine IS-A Animal
Wolf IS-A Canine
Wolf IS-A Animal
With an inheritance tree like the 
one shown here, you’re always 
allowed to say “Wolf extends 
Animal” or “Wolf IS-A Animal”
It makes no difference if Animal 
is the superclass of the superclass 
of Wolf. In fact, as long as Animal 
is somewhere in the inheritance 
hierarchy above Wolf, Wolf IS-A 
Animal will always be true.
The structure of the Animal 
inheritance tree says to the world:
“Wolf IS-A Canine, so Wolf can do 
anything a Canine can do. And 
Wolf IS-A Animal, so Wolf can do 
anything an Animal can do.” 
It makes no difference if Wolf 
overrides some of the methods 
in Animal or Canine. As far as 
the world (of other code) is 
concerned, a Wolf can do those 
four methods. How he does them, 
or 
in which class they’re overridden 
makes no difference. A Wolf can 
makeNoise(), eat(), sleep(), and 
roam() because a Wolf extends 
from class Animal.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   167   168   169   170   171   172   173   174   ...   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